所以,我是 David Hayden 在他的博客 (http://davidhayden.com/blog/dave/archive/2004/02/16/157.aspx) 上发布的方法,通过获取用户的密码来创建盐和散列用户的密码原始密码和生成的盐,并使用 SHA1 对值进行哈希处理。
然后我将盐和散列密码存储在数据库中。
该网站目前是负载平衡的,所以我想知道两台服务器的结果哈希值是否相同。
以下是 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;
}
我问的原因是这段代码使用了代码片段:
FormsAuthentication.HashPasswordForStoringInConfigFile(
saltAndPwd, "sha1");