How to reset password with UserManager of ASP.NET MVC 5

后端 未结 7 1534
情深已故
情深已故 2021-01-30 06:36

I am wondering if there is a way to reset password with UserManager of ASP.NET MVC 5

I tried this with user that already has a password bu

7条回答
  •  遥遥无期
    2021-01-30 07:25

    Try this code .It is working perfectly:

        var userStore = new UserStore();
    
        var userManager = new UserManager(userStore);
    
        string userName= UserName.Text;
    
        var user =userManager.FindByName(userName);
        if (user.PasswordHash != null  )
        {
            userManager.RemovePassword(user.Id);
        }
    
        userManager.AddPassword(user.Id, newpassword);
    

提交回复
热议问题