我试图找出如何使用VerifyHashedPassword方法,这是我到目前为止所得到的。我怎么知道密码是否已经过验证?
public bool VerifyPassword(string pass)
{
PasswordHasher passwordHasher = new PasswordHasher();
HDA = new HWCDA();
HWCE = new HWCEntities();
string userPass = HWCE.AspNetUsers.Where(w => w.UserID == 1).Select(s => s.PasswordHash).FirstOrDefault().ToString();
bool result = false;
passwordHasher.VerifyHashedPassword(userPass, pass);
return false;
}
答案 0 :(得分:5)
VerifyHashedPassword方法返回PasswordVerificationResult,这是一个枚举,可能的值为Failed,Success或SuccessRehashNeeded。你根本没有评估方法的结果。你想要的更像是:
var result = passwordHasher.VerifyHashedPassword(userPass, pass);
return result == PasswordVerificationResult.Success;
您可以查看MSDN docs。