Copied to clipboard

Flag this post as spam?

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


  • Jin Botol 130 posts 282 karma points
    May 25, 2018 @ 01:47
    Jin Botol
    0

    Reset Password with UmbracoIdentity Package

    Hi,

    I'm trying to implement the Reset Password functionality using UmbracoIdentity.

    I got an error in: enter image description here

    I know that this is one of the Limitation of UmbracoIdentity, but I really need this function.

    Here is my code:

       [HttpPost]
       [AllowAnonymous]
       [ValidateAntiForgeryToken]
       public ActionResult ForgotPassword(ResetPasswordViewModel model)
       {
           //generate alpha-numeric string
           var newPassword = MembershipHelpers.GetUniqueKey(10);
    
           var resetmember = UserManager.FindByEmail(model.ResetEmail);
           if (resetmember != null)
           {
               var userId = UserManager.FindByEmail(model.ResetEmail).Id;
    
               UserManager.RemovePassword(userId);
               UserManager.AddPassword(userId, newPassword);
    
               //Send email to the user
               var userEmail = new UserEmail()
               {
                   EmailTo = resetmember.Email,
                   Message = $"You have requested a new password. Your new password is <b>{newPassword}</b>. You will be asked to change your password when you next log in.",
               };
               EmailHelpers.SendEmail(userEmail, "Reset", "Your new password");
    
               return Json(new { status = "true", message = "Check your email..."});
           }
           else
           {
               return Json(new { status = "false");
           }
      }
    

    Thanks,

    Jin

  • Robin Hansen 117 posts 248 karma points
    Dec 10, 2020 @ 14:11
    Robin Hansen
    0

    Hi Jin, I'm facing the exact issue with my Umbraco 8 Solution. Did You manage to solve this - if so, would You care to share...?

    Regards Robin :)

  • Huw Reddick 335 posts 1007 karma points
    Dec 10, 2020 @ 14:58
    Huw Reddick
    0

    If this is for frontend members, I use the MemberService to perform the actual change of the password.

    var memberService = Services.MemberService;
    var member = memberService.GetByEmail(form["email"]);
    
    memberService.SavePassword(member, form["NewPassword"]);
    member.LastPasswordChangeDate = DateTime.UtcNow;
    Services.MemberService.Save(member);
    

    don't know if that is of any help.

  • AquaPecan 1 post 71 karma points
    Dec 11, 2020 @ 10:39
    AquaPecan
    0

    Hi,

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

    ApplicationContext.Current.Services.UserService.SavePassword(user, password);
    

    Official Website

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies