locked
using identity and owin, how can I change a password without knowing the existing password RRS feed

  • Question

  • User-858993849 posted

    I see there is a "reset password" command, and even one that allows you to change it if you know it. But how can I change it if I don't know it?

    Thanks.

    Tuesday, October 11, 2016 6:33 AM

Answers

  • User283571144 posted

    Hi JAYHAWKER,

    I see there is a "reset password" command, and even one that allows you to change it if you know it. But how can I change it if I don't know it?

    According to your description, I suggest you could use UserManager's RemovePassword method remove password firstly.

    Then you could use UserManager's AddPassword add it.

    More details, you could refer to follow codes and link:

      var userId = System.Web.HttpContext.Current.User.Identity.GetUserId();
               if (userId != null)
                {
                    UserManager<IdentityUser> userManager =
               new UserManager<IdentityUser>(new UserStore<IdentityUser>());
                    userManager.RemovePassword(userId);
                    String newPassword = "aaaaaaa";
                    userManager.AddPassword(userId, newPassword);
                }

    Link:

    UserManager's RemovePassword: https://msdn.microsoft.com/en-us/library/dn497511(v=vs.108).aspx

    UserManager's AddPassword: https://msdn.microsoft.com/en-us/library/dn497465(v=vs.108).aspx

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 11, 2016 11:58 AM