简体   繁体   English

ASP.NET:SHA1 +多个服务器上的Salt密码哈希

[英]ASP.NET: SHA1 + Salt Password Hashing on Multiple Servers

So, I am the approach David Hayden posted on his blog (http://davidhayden.com/blog/dave/archive/2004/02/16/157.aspx) to create a salt and hash the user's password by taking the user's raw password and the generated salt and using SHA1 to hash the value. 因此,我是David Hayden在他的博客(http://davidhayden.com/blog/dave/archive/2004/02/16/157.aspx)上发布的一种方法,用于创建盐,并通过获取用户密码来哈希用户密码原始密码和生成的盐,并使用SHA1哈希值。

I then store the salt and the hashed password in the database. 然后,我将盐和哈希密码存储在数据库中。

The website is currently load balanced, so I was wondering if resulting hash value would be the same for both servers. 该网站当前处于负载平衡状态,因此我想知道两个服务器的最终哈希值是否相同。

Here is the snippet of code posted on David Hayden's blog: 这是David Hayden博客上发布的代码片段:

private static string CreateSalt(int size)
  {
   //Generate a cryptographic random number.
   RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
   byte[] buff = new byte[size];
   rng.GetBytes(buff);

   // Return a Base64 string representation of the random number.
   return Convert.ToBase64String(buff);
  }

private static string CreatePasswordHash(string pwd, string salt)
  {
   string saltAndPwd = String.Concat(pwd, salt);
   string hashedPwd =
    FormsAuthentication.HashPasswordForStoringInConfigFile(
    saltAndPwd, "sha1");

   return hashedPwd;
  }

The reason I ask is that this code uses the code snippet: 我问的原因是该代码使用了代码片段:

FormsAuthentication.HashPasswordForStoringInConfigFile(
        saltAndPwd, "sha1");

I think the key question your asking here is if the SHA1 algorithm is the same whatever server it is running on. 我认为您在这里询问的关键问题是SHA1算法在运行的服务器上是否相同。 In which case the answer is yes. 在这种情况下,答案是肯定的。

Presumably you store your generated salt somewhere that all the servers can access it, along with the password hash? 大概您将生成的盐与密码哈希一起存储在所有服务器都可以访问的位置。 So the method used to generate the salt doesn't need to be consistent across servers. 因此,用于生成盐的方法不需要在服务器之间保持一致。

This method will only use the parameters passed into it. 此方法将仅使用传递给它的参数。
Don't worry about it; 不用担心 it will work. 它会工作。

"To address this issue, the validationKey and decryptionKey values must be identical on all computers in the Web farm." “要解决此问题,Web场中的所有计算机上的validationKey和decryptionKey值必须相同。” http://msdn.microsoft.com/en-us/library/ff647070.aspx#pagexplained0002_webfarmscenarios http://msdn.microsoft.com/en-us/library/ff647070.aspx#pagexplained0002_webfarmscenarios

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM