ASP.NET Identity reset password

前端 未结 10 1125
无人及你
无人及你 2020-12-02 05:09

How can I get the password of a user in the new ASP.NET Identity system? Or how can I reset without knowing the current one (user forgot password)?

10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 05:24

    I did a little investigation and the solution that works for me was a mix of a few solutions founded in this post.

    I'm basically compiling this solution and I'm posting what works for me. In my case, I'm don't want to use any token from .net core.

    public async Task ResetPassword(string userId, string password)
    {
        var user = await _userManager.FindByIdAsync(userId);
        var hashPassword= _userManager.PasswordHasher.HashPassword(user, password);
        user.PasswordHash = passwordHash;
        await _userManager.UpdateAsync(user);
    
    }
    

提交回复
热议问题