Search code examples
c#passwordsasp.net-mvc-5reset-passwordusermanager

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


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 but no success. Any clue?

IdentityResult result = UserManager.AddPassword(forgotPasswordEvent.UserId.ToString(), model.ConfirmPassword);
if (result.Succeeded)
{
       //
}
else
{
        AddErrors(result);
}

Solution

  • It is here ASP.NET Identity reset password

    UserManager<IdentityUser> userManager = 
        new UserManager<IdentityUser>(new UserStore<IdentityUser>());
    
    userManager.RemovePassword(userId);
    
    userManager.AddPassword(userId, newPassword);