Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How can I reset password as a admin for other users?

I have tried using the code below

var code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
var result = await UserManager.ResetPasswordAsync(user.Id, code, vm.NewPassword);

when stepping through GeneratePasswordResetTokenAsync, the dispose method of the controller is called.

Can someone please enlighten me?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
369 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can also extend UserManager and expose an explicit AdminChangePassword API that doesn't require any information. Something like this in ApplicationUserManager which extends UserManager should work:

public IdentityResult ChangePasswordAdmin(string userId, string newPassword) {
     var user = FindById(userId);
     // validate password using PasswordValidator.Validate
     user.PasswordHash = PasswordHasher.HashPassword(newPassword);
     Update(user);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...