SQL Server中的哈希密码(asp.net)

时间:2010-05-13 10:06:38

标签: asp.net sql sql-server hash passwords

这样在SQL Server中存储的哈希密码应该是什么样的?

alt text http://img28.imageshack.us/img28/2545/88871034.gif

这是我用来哈希密码的函数(我在一些教程中找到了它)

public string EncryptPassword(string password)
{
    //we use codepage 1252 because that is what sql server uses
    byte[] pwdBytes = Encoding.GetEncoding(1252).GetBytes(password);
    byte[] hashBytes = System.Security.Cryptography.MD5.Create().ComputeHash(pwdBytes);
    return Encoding.GetEncoding(1252).GetString(hashBytes);
}

修改 我尝试使用sha-1,现在字符串看起来像他们想象的那样:

public string EncryptPassword(string password)
{
    return FormsAuthentication.HashPasswordForStoringInConfigFile(password, "sha1");
}

// example output: 39A43BDB7827112409EFED3473F804E9E01DB4A8

上图中的结果看起来像破碎的字符串,但是这个sha-1看起来很正常....

这足够安全吗?

1 个答案:

答案 0 :(得分:3)

你很亲密,但并不完全。

对于安全哈希,您需要在另一列中使用salt值。其次,尽量远离MD5作为哈希提供者。它不如SHA-1或SHA-2安全。 SHA-1包含在.NET中,就像MD5一样。