作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我实现了 IPasswordHasher
public class MyPasswordHasher : IPasswordHasher
{
public string HashPassword(string password)
{
using (SHA256 mySHA256 = SHA256Managed.Create())
{
byte[] hash = mySHA256.ComputeHash(Encoding.UTF8.GetBytes(password.ToString()));
StringBuilder hashSB = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
hashSB.Append(hash[i].ToString("x2"));
}
return hashSB.ToString();
}
}
public PasswordVerificationResult VerifyHashedPassword(
string hashedPassword, string providedPassword)
{
if (hashedPassword == HashPassword(providedPassword))
return PasswordVerificationResult.Success;
else
return PasswordVerificationResult.Failed;
}
}
我写在IdentityConfig
manager.PasswordHasher = new MyPasswordHasher();
但是 var user = await UserManager.FindAsync(model.Email, model.Password);
在 AccountController/Login 中不要使用 MyPasswordHaser。
如何在 Identity 2.1 中使用它?
最佳答案
您必须将其插入到 UserManager 中:
public class AppUserManager : UserManager<AppUser, int>
{
public AppUserManager(AppUserStore a_store)
: base(a_store)
{
_container = a_container;
_emailService = _container.GetInstance<IEmailService>();
PasswordHasher = new AppPasswordHasher();
}
}
关于c# - 如何使用自定义 IPasswordHasher?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26505446/
我实现了 IPasswordHasher public class MyPasswordHasher : IPasswordHasher { public string HashPasswor
我是一名优秀的程序员,十分优秀!