I am new to Web API ,Here I am working in a token based authentication . I done all the login and Signup process with AspNetUsers table except the update password functionalities.
Here I have updated the HashedPassword field by passing the new password .When I try to get token for the specific user it returns some error related with passwordHash format because it directly save the new password without hash.
code :
public string updateUserData(string mEmail,string mPassword)
{
if (ModelState.IsValid)
{
var userStore = new UserStore<ApplicationUser>(new ApplicationDbContext());
var manager = new UserManager<ApplicationUser>(userStore);
ApplicationUser AppModel = manager.FindByEmail(mEmail);
AppModel.PasswordHash = mPassword;
manager.Update(AppModel);
return "Success";
}
return "Update Failed";
}
can anyone help me to do this in a proper way .I am new to this if I did any silly mistake I am asking sorry for that.
create a password reset token and then use that to change the password. Example:
var user = await manager.FindByIdAsync(id);
var token = await manager.GeneratePasswordResetTokenAsync(user);
var result = await manager.ResetPasswordAsync(user, token, "NewPassword");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.