[英]How to update password for the existing user record in AspNetUsers table from WebAPI
I am new to Web API ,Here I am working in a token based authentication . 我是Web API的新手,在这里我正在基于令牌的身份验证中工作。 I done all the login and Signup process with AspNetUsers table except the update password functionalities.
除更新密码功能外,我使用AspNetUsers表完成了所有登录和注册过程。
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. 在这里,我通过传递新密码来更新了HashedPassword字段。当我尝试获取特定用户的令牌时,它会返回与passwordHash格式有关的一些错误,因为它直接保存了新密码而没有哈希值。
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");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.