简体   繁体   English

asp.net 身份与自定义密码哈希

[英]asp.net identity with custom password hasher

so I'm trying to get asp.net to work with a custom passwordhasher.所以我试图让 asp.net 使用自定义密码哈希器。 the registration works when I change the hasher with the following code当我使用以下代码更改哈希器时,注册有效

IPasswordHasher hasher = new CustomPassword();

UserManager.PasswordHasher = hasher;

but the sign in method keep saying my credentials don't exist when using the following code for the login method in the acountcontroller但是在 acountcontroller 中使用以下代码作为登录方法时,登录方法一直说我的凭据不存在

IPasswordHasher hasher = new CustomPassword();

SignInManager.UserManager.PasswordHasher = hasher;

am I missing something?我错过了什么吗?

I had a similar issue, and the answer was not obvious.我有一个类似的问题,答案并不明显。 This was done in.Net6 but I believe should be the same for whatever version you are using.这是在 .Net6 中完成的,但我相信对于您使用的任何版本都应该是相同的。

You need to make sure you add the passwordhasher before the call to AddIdentity您需要确保在调用 AddIdentity 之前添加 passwordhasher

builder.Services.AddTransient<IPasswordHasher<ApplicationUser>, PasswordHasherService>();

builder.Services.AddIdentity<ApplicationUser, IdentityRole>()

SigninManager will then use the password hasher you defined instead of the default one. SigninManager 然后将使用您定义的密码散列器而不是默认的散列器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM