0

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.

Zhu
  • 3,679
  • 14
  • 45
  • 76

1 Answers1

0

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");
Roxana Sh
  • 294
  • 1
  • 3
  • 14