对于非 Web 应用程序,什么会给我带来与 FormsAuthentication 哈希相同的结果?
我编写了一个快速控制台应用程序,可以为没有正确散列密码的现有帐户快速生成 Web 应用程序的用户名和登录名。 在我的网络应用程序中,我使用 FormsAuthentication,如下所示:
string hashedPwd = FormsAuthentication.HashPasswordForStoringInConfigFile(saltAndPassword, "SHA1");
我尝试在控制台应用程序中使用 FormsAuthentication,但它无法解析 FormsAuthentication 或导入。 我收到的警告询问我是否缺少程序集。 我尝试使用以下方法来获得与之前相同的结果:
SHA1 sha1 = new SHA1CryptoServiceProvider();
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] bytesHashedPwd = sha1.ComputeHash(encoding.GetBytes(saltAndPwd));
string tmpString = encoding.GetString(byteshashedPwd);
string hashedPwd = String.Concat(str, salt);
return hashedPwd;
这两种方法给了我不同的结果。 我需要获得与 FormsAuthentication 相同的结果。 我不是一个没有什么浮夸背景的安全专家,我的字符集知识更糟糕。 我感谢任何帮助。
I have written a quick console app to quickly go and generate usernames and logins for my web application for existing accounts that did not have properly hashed passwords. In my web application I am using FormsAuthentication like so:
string hashedPwd = FormsAuthentication.HashPasswordForStoringInConfigFile(saltAndPassword, "SHA1");
I tried to use FormsAuthentication in the console app but it cannot resolve the FormsAuthentication nor the imports. The warning I get asks if I am missing an assembly. I tried to use the following to give me the same results as the previous:
SHA1 sha1 = new SHA1CryptoServiceProvider();
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] bytesHashedPwd = sha1.ComputeHash(encoding.GetBytes(saltAndPwd));
string tmpString = encoding.GetString(byteshashedPwd);
string hashedPwd = String.Concat(str, salt);
return hashedPwd;
These two methods are giving me different results. I need to get the same result as FormsAuthentication. I am no security expert with a tiny vauge background and my character set knowledge is even worse. I apprecaite any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这似乎对我有用。
然后我使用了您的代码片段:
来获取结果。 这是在控制台应用程序中。
It seems to work for me.
Then I used your code snippet:
To get the result. This was in a console application.
如果您好奇,该方法使用的代码是:
If you're curious, the code used by that method is:
这是在 C# 中避免 System.Web.dll 依赖性的另一个解决方案:
您可以像这样使用它:
Here's another solution to avoid the System.Web.dll dependency, in C#:
You'd use it like this:
我能够将 System.Web 引用添加到控制台应用程序并使用
I was able to add the System.Web reference to a console app and use
这里很好地解释了如何匹配格式。 希望能帮助到你。
http://www.stardeveloper.com/articles/display。 html?article=2003062001&page=1
我相信区别在于表单身份验证将其哈希为十六进制字符串。
Here is a good explanation of how to match the format. Hope it helps.
http://www.stardeveloper.com/articles/display.html?article=2003062001&page=1
I believe the difference is the forms authentication hashes it to a hexadecimal string.