ASP.NET Core password reset token lifetime (2024)

Suggested Videos
Part 115 -Forgot password in asp.net core | Text | Slides
Part 116 -Reset password in asp.net core | Text | Slides
Part 117 -How tokens are generated and validated in asp.net core | Text | Slides

In this video we will discuss, how to set password reset token lifetime i.e specifying how long the token will be valid.

This is continuation to our previous video Part 117. Please watch Part 117 from asp.net core tutorial.


Both, password reset token and email confirmation token are generated by the built-in DataProtectorTokenProvider class. In our previous video, we discussed in detail, how this class generates and validates these tokens.

So, it is the DataProtectorTokenProvider class that generates the password reset token. The token life span is controlled by DataProtectionTokenProviderOptions class. You can see this yourself, if you look at the source code of DataProtectorTokenProvider class at the following link.
https://github.com/aspnet/Identity/blob/release/2.2/src/Identity/DataProtectionTokenProvider.cs


The default token life span is 1 day. You can see this yourself if you look at the source code of DataProtectionTokenProviderOptions class at the following link.
https://github.com/aspnet/Identity/blob/release/2.2/src/Identity/DataProtectionTokenProviderOptions.cs

From security standpoint, password reset token is a bit sensitive so it make sense to reduce the time it is valid for. The following code sets the token life span to 5 hours.

public void ConfigureServices(IServiceCollection services)
{
// rest of the code

services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
options.Password.RequiredLength = 10;
options.Password.RequiredUniqueChars = 3;

options.SignIn.RequireConfirmedEmail = true;
})
.AddEntityFrameworkStores<AppDbContext>()
.AddDefaultTokenProviders();

// Set token life span to 5 hours
services.Configure<DataProtectionTokenProviderOptions>(o =>
o.TokenLifespan = TimeSpan.FromHours(5));

// rest of the code
}


The above code, not only sets password reset token life span to 5 hours. It also sets the life span of all the tokens generated by DataProtectorTokenProvider class to 5 hours. This may not be the behaviour you want. For example, the email confirmation token is also generated by DataProtectorTokenProvider class. So this means even the email confirmation token life span is 5 hours.

In general email confirmation tokens can live a little longer than password reset tokens. For example, let's say we want to change the life span of email confirmation token to 3 days. To achieve this we have to create a custom DataProtectorTokenProvider and DataProtectionTokenProviderOptions.

We will discuss how to do this in our next video.

ASP.NET Core password reset token lifetime (1)

ASP.NET Core password reset token lifetime (2024)

FAQs

ASP.NET Core password reset token lifetime? ›

Brute force attacks

To prevent this, we must ensure that tokens are generated using a secure random source, and that they are long enough (we recommend >= 64 characters).

How long should a password reset token be? ›

Brute force attacks

To prevent this, we must ensure that tokens are generated using a secure random source, and that they are long enough (we recommend >= 64 characters).

How to generate token for reset password in C#? ›

Use the ResetPassword() method if the user has forgotten his password. The ResetPassword() method requires a password reset token. A confirmation token can be created by the CreateAccount(), CreateUserAndAccount(), or GeneratePasswordResetToken() methods.

How to reset password in ASP.NET Core? ›

Test password reset
  1. If you're signed in, select Logout.
  2. Select the Log in link and select the Forgot your password? link.
  3. Enter the email you used to register the account.
  4. An email with a link to reset your password is sent. Check your email and click the link to reset your password.
Mar 27, 2023

What is a token when resetting a password? ›

For security reasons, passwords are never sent out across the Internet. Instead a token will be sent to your email instead. A token is a one-time generated link that contains numbers and letters that'll allow you to reset your password. It cannot be reused and is only valid for seven days.

What is the lifetime of password reset token? ›

The default token life span is 1 day. You can see this yourself if you look at the source code of DataProtectionTokenProviderOptions class at the following link. From security standpoint, password reset token is a bit sensitive so it make sense to reduce the time it is valid for.

When should a password reset link expire? ›

Password reset links expire after 24 hours from when it's triggered. Email change verification links expire after 72 hours from the time of change. Note: The password reset link expiration is different from the password expiration set in Password Policies.

What are the password rules for asp net core? ›

Password. By default, Identity requires that passwords contain an uppercase character, lowercase character, a digit, and a non-alphanumeric character. Passwords must be at least six characters long.

How to change authentication in asp net Core? ›

New project
  1. Create a new project.
  2. Select ASP.NET Core Web Application. Select Next.
  3. Provide a name in the Project name field. ...
  4. Select Change under Authentication.
  5. In the Change Authentication window, select Windows Authentication. ...
  6. Select Web Application.
  7. Select Create.
Apr 25, 2023

How to set validation for password in asp net? ›

Creating Custom Password Validator in ASP.NET Identity:
  1. Password should be of minimum 8 Characters.
  2. It should have both Upper-Case (A-Z) and Lower-Case Characters (a-z).
  3. Password should contain at least one digit (0-9).
  4. Password should contain at least one special character (! @#$%^&*).

Why is my password reset token not valid? ›

Cause. This error will appear because you have opened an older email and have tried to use an expired token to reset your password. Whenever you attempt to reset your password, it will send you an email with a new token and will expire any older email tokens that have been sent to you previously.

How to generate a password reset token? ›

Create a password reset token.

The token is expressed as the 'password_reset_url' of the user's email/password credential object. This takes an optional 'expires' param to indicate if the new token should be an expiring token. Tokens that expire are typically used for self-service password resets for existing users.

Why use token instead of password? ›

Tokens streamline the login process: Authentication tokens ensure that users do not have to re-enter their login credentials every time they visit a website. This makes the process quicker and more user-friendly, which keeps people on websites longer and encourages them to visit again in the future.

How long is the password reset token in laravel? ›

By default, password reset tokens expire after one hour. You may change this via the password reset expire option in your config/auth.

Why is my reset password token invalid? ›

Cause. This error will appear because you have opened an older email and have tried to use an expired token to reset your password. Whenever you attempt to reset your password, it will send you an email with a new token and will expire any older email tokens that have been sent to you previously.

Should password reset tokens be hashed? ›

Yes, you should hash password reset tokens, exactly for the reasons you mentioned. users notice when their passwords are changed, but not when their passwords are cracked, and can thus take steps to limit the damage (change password and other sensitive data, etc).

Top Articles
ZkSync Price Analysis: What To Do As Airdrop Threatens ZK Sell-Off To Zero
Come investire nella tecnologia Blockchain, azioni e boom
No Hard Feelings Showtimes Near Metropolitan Fiesta 5 Theatre
Part time Jobs in El Paso; Texas that pay $15, $25, $30, $40, $50, $60 an hour online
PRISMA Technik 7-10 Baden-Württemberg
Puretalkusa.com/Amac
123 Movies Babylon
Es.cvs.com/Otchs/Devoted
Purple Crip Strain Leafly
Craigslist Cars Nwi
Babyrainbow Private
Breakroom Bw
Summoner Class Calamity Guide
Nalley Tartar Sauce
Guidewheel lands $9M Series A-1 for SaaS that boosts manufacturing and trims carbon emissions | TechCrunch
Gon Deer Forum
7543460065
Best Nail Salon Rome Ga
Craigslist Portland Oregon Motorcycles
Zack Fairhurst Snapchat
Craigslist Missoula Atv
Abby's Caribbean Cafe
Craigslist Southern Oregon Coast
Ein Blutbad wie kein anderes: Evil Dead Rise ist der Horrorfilm des Jahres
Jenna Ortega’s Height, Age, Net Worth & Biography
Cincinnati Adult Search
Bidevv Evansville In Online Liquid
Meridian Owners Forum
Poochies Liquor Store
Farm Equipment Innovations
Pronóstico del tiempo de 10 días para San Josecito, Provincia de San José, Costa Rica - The Weather Channel | weather.com
2430 Research Parkway
Muma Eric Rice San Mateo
Build-A-Team: Putting together the best Cathedral basketball team
Ludvigsen Mortuary Fremont Nebraska
Boone County Sheriff 700 Report
Hindilinks4U Bollywood Action Movies
Directions To Advance Auto
Pay Entergy Bill
Join MileSplit to get access to the latest news, films, and events!
Casamba Mobile Login
Sour OG is a chill recreational strain -- just have healthy snacks nearby (cannabis review)
Watch Chainsaw Man English Sub/Dub online Free on HiAnime.to
Blow Dry Bar Boynton Beach
Canvas Elms Umd
Amateur Lesbian Spanking
Rocket League Tracker: A useful tool for every player
Sam's Club Gas Price Sioux City
R Detroit Lions
Fallout 76 Fox Locations
Unity Webgl Extreme Race
Latest Posts
Article information

Author: Lidia Grady

Last Updated:

Views: 6041

Rating: 4.4 / 5 (65 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Lidia Grady

Birthday: 1992-01-22

Address: Suite 493 356 Dale Fall, New Wanda, RI 52485

Phone: +29914464387516

Job: Customer Engineer

Hobby: Cryptography, Writing, Dowsing, Stand-up comedy, Calligraphy, Web surfing, Ghost hunting

Introduction: My name is Lidia Grady, I am a thankful, fine, glamorous, lucky, lively, pleasant, shiny person who loves writing and wants to share my knowledge and understanding with you.