Copied to clipboard

Flag this post as spam?

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


  • Dean 13 posts 123 karma points
    May 16, 2023 @ 18:50
    Dean
    0

    How to check if password link has expired

    Hi

    I'm creating a password link for a member listed under the member section in Umbraco 10.

    According to the docs the link is valid for only 24 hours. How could I check if the link sent has expired?

    Thanks

  • Marcio Goularte 374 posts 1346 karma points
    May 16, 2023 @ 19:30
    Marcio Goularte
    100

    Hi, as far as I know the members section has no way of seeing when the link will expire. What you can do is when generating the code save this expiration time in a property.

    var member = _memberService.GetByEmail(model.EmailAddress);
    member.SetValue("tokenExpires",  DateTime.UtcNow.AddHours(24));
    _memberService.Save(member);
    

    And when you reset the member's code, you can clear that date

    var result = await _memberManager.ResetPasswordAsync(identityUser, resetCode, newPassword);
            if (result.Succeeded) 
    { 
    
    var member = _memberService.GetByEmail(model.EmailAddress);
    member.SetValue("tokenExpires",  null);
    _memberService.Save(member);
    
     }
    

    It is possible to do this better by injecting the DataProtectionTokenProviderOptions and setting the date according to what is configured and not as I described there, fixed 24 hours. But if you want to share more code context we can see how it looks

Please Sign in or register to post replies

Write your reply to:

Draft