Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
}
like image 789
Friend Avatar asked Mar 19 '14 19:03

Friend


People also ask

How to reset password in ASP net c#?

Run the "ForgotPassword. aspx" page and enter username or email id and click on submit button.It will send reset password link on your email id. Check your email and click on the reset password link. You will be redirected to the "ResetPassword.


2 Answers

It is here ASP.NET Identity reset password

UserManager<IdentityUser> userManager = 
    new UserManager<IdentityUser>(new UserStore<IdentityUser>());

userManager.RemovePassword(userId);

userManager.AddPassword(userId, newPassword);
like image 155
Friend Avatar answered Oct 19 '22 10:10

Friend


I suppose this is newer but there is such an API in Identity 2.0:

IdentityResult result = await UserManager.ResetPasswordAsync(user.Id, model.Code, model.Password);

model.Code is generated the following way, and you should send this as a link in a email to make sure the user who is claiming to want to change the password is that one that owns the email address:

string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
like image 31
Yan Avatar answered Oct 19 '22 10:10

Yan