Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mila Pandurska 43 posts 190 karma points
    Mar 22, 2018 @ 15:20
    Mila Pandurska
    0

    Reset Password with UmbracoIdentity

    Hi, I'm trying to imaplement Reset password functionality using UmbracoIdentity. I have created a method to send email with a key to reset. When user clicks on the link it redirects him to /reset-password?resetPasswordGUID=123 where the user needs to enter email address and new password. The problem is that I cannot save the new password. I know that this is one of the limitations of UmbracoIdentity and it is not implemented, but I need this functionality. Here is my code in HandleResetPassword method:

    [HttpPost]
            [AllowAnonymous]
            [ValidateAntiForgeryToken]
            public ActionResult HandleResetPassword(ResetPasswordViewModel model)
            {
                if (!ModelState.IsValid)
                {
                    return PartialView("ResetPassword", model);
                }
    
                var resetMember = UserManager.FindByEmail(model.Email);
    
                if (resetMember != null && !string.IsNullOrEmpty(model.Code))
                {   
                    var resetPassProperty = resetMember.MemberProperties.Find(p => p.Alias == "resetPasswordGUID");
                    if (resetPassProperty != null && resetPassProperty.Value == model.Code)
                    {                          
    
                        //TODO: Change Password
                        return Redirect("/login");
                    }
                    else
                    {
                      ....
                    }
                }
                else
                {
                    ...
                }
                return PartialView("ResetPassword", model);
            }
    
  • Rhys Hamilton 140 posts 942 karma points
    Mar 22, 2018 @ 15:34
    Rhys Hamilton
    0

    Hi Mila,

    You should be able to change the User's password with the following line of code.

    ApplicationContext.Current.Services.UserService.SavePassword(user, password);
    
  • Mila Pandurska 43 posts 190 karma points
    Mar 22, 2018 @ 16:13
    Mila Pandurska
    0

    Hi, Rhys, I'm trying to reset password for Members and I already tried this

    ApplicationContext.Current.Services.MemberService.SavePassword(member, model.Password);
    

    This doesn't work. In my example above UserManager is the manager from UmbracoIdentity.

  • Steve Morgan 1346 posts 4453 karma points c-trib
    Mar 22, 2018 @ 17:13
    Steve Morgan
    0

    HI Mila,

    Take a look at this thread - you may need to update the web.config. Add teh attribute allowManuallyChangingPassword="false" * in your web.config file on the* UmbracoMembershipProvider

    https://our.umbraco.org/forum/extending-umbraco-and-using-the-api/85722-problem-updating-members-password-using-umbraco-version-761

    HTH

    Steve

  • Mila Pandurska 43 posts 190 karma points
    Mar 23, 2018 @ 14:12
    Mila Pandurska
    0

    Hi, Steve, I already tried changing this value. The problem is that I use UmbracoIdentity (https://github.com/Shazwazza/UmbracoIdentity) not the standart UmbracoMembership.

    Thanks Mila

  • Rhys Hamilton 140 posts 942 karma points
    Mar 23, 2018 @ 14:36
    Rhys Hamilton
    100

    Hi Mila,

    Does the UserManager happen to have any methods for removing or adding a password?

    I'm assuming that since the UmbracoIdentity allows for the use of OWIN & ASP.Net Identity, there's some kind of inheritance somewhere.

    You could possibly remove the existing password, then add a new one, as a workaround?

    I'd suspect you'd be looking for the following methods in UserManager

    • .RemovePassword(userId)
    • .AddPassword(userId, newPassword)

    Hopefully this helps.

  • Mila Pandurska 43 posts 190 karma points
    Mar 23, 2018 @ 20:47
    Mila Pandurska
    1

    Hi Rhys, You gave me the idea to look all the methods in UserManager (which should be the first thing to do in the first place). I have managed to achieve reset password functionality using

    UserManager.ResetPassword(Id, resetPasswordTken, newPassword);
    

    resetPasswordToken is generated with

    UserManager.GeneratePasswordResetToken(Id)
    

    Honestly I expected much more complicated solution. I cannot believe it is so simple.

    Mila

  • Jin Botol 134 posts 287 karma points
    May 24, 2018 @ 08:31
    Jin Botol
    1

    Hi Mila,

    I have the same problem as yours. I'm new in Umbraco and ASP.

    Can I post the whole method did you use? Because I'm stuck in RemovePassword(UserId)

    Please, thanks in advance.

    Jin

Please Sign in or register to post replies

Write your reply to:

Draft