因此,我是David Hayden在他的博客上发布的方法(http://davidhayden.com/blog/dave/archive/2004/02/16/157。 aspx)创建一个salt并通过获取用户的原始密码和生成的salt并使用SHA1对值进行散列来散列用户的密码。ASP.NET:SHA1 +多个服务器上的盐密码散列
然后我将salt和哈希密码存储在数据库中。
该网站目前是负载平衡,所以我想知道如果产生的哈希值将是相同的两台服务器。
这里的代码张贴在大卫·海登的博客摘录:
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;
}
我想问的原因是,此代码使用的代码片段:
FormsAuthentication.HashPasswordForStoringInConfigFile(
saltAndPwd, "sha1");
不要将盐限制为ASCII字符。 – SLaks 2011-02-08 19:09:29
我喜欢`Rfc2898DeriveBytes`与每个用户和每个应用程序salt。 – CodesInChaos 2011-02-08 19:10:26