ASP.NET Identity reset password

前端 未结 10 1078
无人及你
无人及你 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条回答
  •  遥遥无期
    2020-12-02 05:28

    Deprecated

    This was the original answer. It does work, but has a problem. What if AddPassword fails? The user is left without a password.

    The original answer: we can use three lines of code:

    UserManager userManager = 
        new UserManager(new UserStore());
    
    userManager.RemovePassword(userId);
    
    userManager.AddPassword(userId, newPassword);
    

    See also: http://msdn.microsoft.com/en-us/library/dn457095(v=vs.111).aspx

    Now Recommended

    It's probably better to use the answer that EdwardBrey proposed and then DanielWright later elaborated with a code sample.

提交回复
热议问题