我正在尝试弄清楚如何使用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;
}
verifyhashedpassword方法返回一个passwordverificationResult,该方法是具有失败,成功或成功的枚举。您根本不评估该方法的结果。您想要的更像是:
var result = passwordHasher.VerifyHashedPassword(userPass, pass);
return result == PasswordVerificationResult.Success;
您可以检查MSDN文档。