20

I'm trying to extend the lifespan of both confirmation emails and password reset emails but I can't manage to do so. Currently I'm using Asp.net core 1.0.1 if that's helpful.

Some tips or even better, the code, would be much appreciated.

Thank you

Gzim Helshani
  • 527
  • 1
  • 5
  • 15

2 Answers2

38

Maybe it will help someone=)

Just do this:

    public void ConfigureServices(IServiceCollection services)
    {
        // ...
        services.Configure<DataProtectionTokenProviderOptions>(options =>
        {
            options.TokenLifespan = TimeSpan.FromDays(2); // Sets the expiry to two days
        });
    }

This works for me.

Viacheslav Yankov
  • 988
  • 10
  • 19
  • 1
    it's not working in my project. I am using .Net Core 3.1 – Zubair Rana Sep 16 '20 at 07:57
  • 4
    Wouldn't this also increase the LifeSpan of the PasswordRest token? I'm pretty sure EmailConfirmation and PasswordReset tokens both use the same instance of DataProtectionTokenProvider. – O.MeeKoh Jun 11 '21 at 14:33
2

The following code change in the Create method (in the App_Start\IdentityConfig.cs file) sets the tokens to expire in 3 hours.

if (dataProtectionProvider != null)
 {
    manager.UserTokenProvider =
       new DataProtectorTokenProvider<ApplicationUser>
          (dataProtectionProvider.Create("ASP.NET Identity"))
          {                    
             TokenLifespan = TimeSpan.FromHours(3)
          };
 }

Hope this helps.

Sridhar
  • 55
  • 5