简体   繁体   中英

How do I administratively set a new password for ASP.net Identity User who forgot their password?

I am not looking for a solution that involves the user, a token generated, and emailing in order to reset a user's password.

The scenario is a user contacts the admins and asks them to reset their password (internal organization web app). They are then told what that new temporary password is so they can log in and change it.

I see no function that lets me do the above. My attempt:

string passwordToken = await UM.GeneratePasswordResetTokenAsync(user.Id);

IdentityResult res = await UM.ResetPasswordAsync(user.Id, passwordToken, "newPassword#@!$%"); 

UM is UserManager.

I get error "No IUserTokenProvider is registered". I think GeneratePasswordResetToken is the one causing the error. If so, why?

How do I properly do what I need?

Use the combination of RemovePasswordAsync and AddPasswordAsync

UserManager.RemovePasswordAsync(user.Id);
UserManager.AddPasswordAsync(user.Id, tempPassword);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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