【发布时间】:2016-09-13 14:28:37
【问题描述】:
使用以下函数,您可以使用 bcrypt 加密输入字符串。
public static string CreatePassword(string password)
{
// no need to provide a Salt value since bcrypt does that automatically
byte[] PasswordBytes = Encoding.ASCII.GetBytes(password);
return Crypter.Blowfish.Crypt(PasswordBytes);
}
这使用了CryptSharp,这很棒,但是如何根据此函数返回的哈希验证用户输入?
我在库中找不到执行此操作的任何函数。
我能想到的最好方法是:
public static bool ValidatePassword(string password, string passwordHash)
{
// crypt the entered password
string Crypted = Crypter.Blowfish.Crypt(Encoding.ASCII.GetBytes(password));
// compare the crypted password against the value in the database
if (String.Compare(Crypted, passwordHash, false) != 0) return false;
return true;
}
唯一的问题是盐值不一样,因此值几乎总是不一致。
【问题讨论】:
-
你为什么不使用相同的盐来输入和存储密码
标签: c# cryptsharp