Copied to clipboard

Flag this post as spam?

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


  • Ranjit J. Vaity 66 posts 109 karma points
    Dec 27, 2020 @ 20:20
    Ranjit J. Vaity
    0

    Umbraco 8 - Generate Password Reset Token (a .NET feature)

    Dear Community,

    I am working on a feature where if registered member forgets the password. he should be able to get a password reset link via email where the password can be changed.

    I have seen ASP.NET features where this can be easily done as below:

    string token = WebSecurity.GeneratePasswordResetToken(UserName);
    

    Where this code/token can be send in the link as qs parameter and when member clicks the link, options for setting new password can be provided.

    Finally with this code/token to reset a new password for that member/user as below:

    bool resetResponse = WebSecurity.ResetPassword(model.ReturnToken, model.Password);
    

    I was trying to search for such feature in our api be unable to located any. If I could get some help or guidance or any alternative to this feature provided would be great.

    Thank you in advance!

    Best Regards,

    Ranjit

  • Huw Reddick 1932 posts 6722 karma points MVP 2x c-trib
    Dec 28, 2020 @ 17:33
    Huw Reddick
    1

    I added a couple of properties to the member and use those to store a token

    for the token I just generate a guid and strip the '-' I then store it against the members profile and send them an email, when they click the confirmation link, I check the created token and give them a form where they can set a new password.

            var token = GenerateUniqueCode();
            user.SetValue("confirmationToken", token);
            user.SetValue("tokenExpires", DateTime.UtcNow.AddHours(48));
            memberService.Save(user);
    

    In the handler for the reset form, I do the following

            #region reset the Umbraco password
            //there was a password, so lets do the reset
            memberService.SavePassword(member, form["NewPassword"]);
            member.LastPasswordChangeDate = DateTime.UtcNow;
    
            //remove the token and expiry
            member.SetValue("confirmationToken", "");
            member.SetValue("tokenExpires", DateTime.UtcNow.AddDays(-30));
            Services.MemberService.Save(member);
            #endregion
    
  • Ranjit J. Vaity 66 posts 109 karma points
    Dec 29, 2020 @ 14:57
    Ranjit J. Vaity
    0

    Hi Huw,

    Sounds good!

    I tried this and works like charm... :)

    Thank you very much!

    Regards,

    Ranjit

  • Huw Reddick 1932 posts 6722 karma points MVP 2x c-trib
    Dec 29, 2020 @ 18:04
    Huw Reddick
    0

    Glad to be of help.

  • 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