且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.NET Core将辅助密码添加到IdentityUser

更新时间:2023-02-16 23:42:14

您可以使用

You can use the IPasswordHasher interface , when the user registers , you can create the password hash that will be stored in the database(PIN property) , when you need to verfiy , to hash the provided password/PIN and compare it to the stored hash .

例如,使用DI来包含扩展名:

For example , use DI to involve the extension :

public readonly IPasswordHasher<ApplicationUser> _passwordHasher;
public HomeController(IPasswordHasher<ApplicationUser> passwordHasher )
{
    _passwordHasher = passwordHasher;
}

要创建哈希密码:

var hasedPassword = _passwordHasher.HashPassword(null,"Password");

要验证:

var successResult = _passwordHasher.VerifyHashedPassword(null, hasedPassword , "Password");

您还可以参考文档: 查看全文