Identity 2.0 Reset password by Admin

前端 未结 2 1346
一生所求
一生所求 2020-12-19 06:39

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

I have tried using the code below

var code = await UserManager.GeneratePasswordResetTokenAsync(u         


        
相关标签:
2条回答
  • 2020-12-19 06:50

    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);
    }
    
    0 讨论(0)
  • 2020-12-19 07:05

    I should have searched more before posting question here.

    Apparently I need to wire up UserTokenProvider with a DataProtectorTokenProvider.

    However I do not understand what's a DataProtector for, would be glad if someone can explain here.

    var dataProtectionProvider = options.DataProtectionProvider;
    if (dataProtectionProvider != null)
    {
        manager.UserTokenProvider = new DataProtectorTokenProvider<MyUser>(dataProtectionProvider.Create("ASP.NET Identity"));
    }
    

    Answer is found here

    0 讨论(0)
提交回复
热议问题