Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure confirmation email token lifespan in asp.net core mvc

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

like image 319
Gzim Helshani Avatar asked May 17 '17 13:05

Gzim Helshani


People also ask

How do I reset my net core password?

A user clicks on the Forgot password link and gets directed to the view with the email field. After a user populates that field, an application sends a valid link to that email. An email owner clicks on the link and gets redirected to the reset password view with the generated token.


2 Answers

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.

like image 146
Viacheslav Yankov Avatar answered Nov 10 '22 19:11

Viacheslav Yankov


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.

like image 2
Sridhar Avatar answered Nov 10 '22 19:11

Sridhar