简体   繁体   English

如何从WebAPI更新AspNetUsers表中现有用户记录的密码

[英]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.

相关问题 如何在现有AspNetUsers表中添加列 - How to add a column in an existing AspNetUsers table 如何根据MVC.NET中AspNetUsers表中的哈希值验证用户密码? - How to verify user's password against hash value in AspNetUsers table in MVC.NET? 如何从AspNetUsers表中获取自定义ID - How to get custom Id from AspNetUsers table 如何向User.Identity添加另一个Propertys来自身份2.2.1中的表AspNetUsers - How to Add another Propertys to User.Identity From table AspNetUsers in identity 2.2.1 如何更新现有记录并在SQL表中插入新记录? 的SQL - How to Update existing record and insert new record in SQL table ? SQL 使用存储过程从 AspNetUsers 表中检索所有或单个用户 - Using a stored procedure to retrieve all or single user from AspNetUsers table 使用单个用户帐户时如何在AspNetUsers表中设置PhoneNumber - How to set PhoneNumber in AspNetUsers table when using individual user accounts 如何在AspNetUsers表中保存字段 - How to save a field in the AspNetUsers table 如何从 dbo.AspNetUsers 表中读取数据? - How do I read from the dbo.AspNetUsers table? 在我的ASPNETUsers表中创建“假”用户 - Create “fake” user in my ASPNETUsers Table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM