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 134 posts 287 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 135 posts 368 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 1737 posts 6098 karma points MVP c-trib
    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.

Please Sign in or register to post replies

Write your reply to:

Draft