← All articlesWeb security

How to Design Password Resets: Link Expiration, Single Use, and Sessions

Designing a password reset requires defining the entire journey, from requesting a link to the next login. A time limit alone is not enough: the token must belong to a specific user and become invalid after use. Existing sessions require a separate decision. Here are the rules to build into a web application and how to check them using test accounts you own.

Where the Trust Boundary Lies

A recovery request does not yet authorize changes to an account’s state. For example, the account must not be locked before a valid token is presented. This is an important boundary between submitting a recovery request and establishing the right to continue a password reset.

Separate these stages explicitly in the product requirements: the user requests recovery, presents a valid token, sets a new password, and then signs in through the normal login process. Describe the expected result for each stage. This makes it easier for developers and reviewers to see what authorizes the application to allow a change.

Link Expiration and Single Use

OWASP recommends single-use tokens with an appropriate expiration period, but the cited recommendation does not specify a number of minutes. Document the chosen period as a product decision rather than presenting it as a universal requirement of a standard. The specification should make clear when the link stops being accepted.

Expiration and prior use are separate reasons to reject a token. Once a token has been used for a successful reset, it must become invalid even if its allotted time has not elapsed. Single use does not mean a link cannot be intercepted: this rule limits its reuse after it has been used.

Token Generation and User Association

Recovery tokens and codes should be created using a cryptographically secure random number generator. A token must be associated with a specific user in the database and invalidated after use. Check these requirements separately: the generation method does not replace account association or validity checks.

For the implementation, define three questions: which user owns the token, has it expired, and has it already been used? If the current implementation omits any of these conditions, add the corresponding check to reset processing. The mere presence of a value in the link does not answer these questions.

What Happens to Sessions After a Password Reset

For a routine reset, OWASP offers two options: ask the user whether to end all existing sessions, or end them automatically. Choose the behavior in advance and reflect it in the interface. This outcome must not be left as an accidental consequence of the implementation.

Recovery of a potentially compromised account requires a separate flow: after successful recovery, existing sessions and any remaining reset and recovery links or codes should be invalidated. Keep this requirement distinct from the choice allowed for a routine reset. Specify which scenario each recovery path serves.

Notifications, Normal Login, and Changes Within an Active Session

After a reset, email the user a notification that their password has changed, without including the password itself. Then direct them to the normal login mechanism: automatically signing the user in after they set a new password is not recommended. Password reset and account recovery are high-risk events after which reauthentication matters.

Changing a password within an active session is a separate feature. It requires checking the current password to confirm that the legitimate user is making the change. Do not apply this condition indiscriminately to forgotten-password recovery: the two scenarios have different starting conditions.

A Fictional Example and Safe Testing

Imagine a fictional web service called Notebook and two test accounts owned by the team. Issue a link for the first account, successfully change its password, and open the same link again. The expected result is that another reset is unavailable. Test a separate link after the product’s defined expiration period: it should also be rejected.

Using the same test data, check that the token is associated with the correct account and that the account’s state does not change before a valid token is presented. After the reset, check the email contains no password, the user is directed to normal login, and sessions behave as specified. For the potential-compromise scenario, also confirm that previous sessions and any remaining reset and recovery links or codes have been invalidated.

Fix Priorities and Testing Limits

First, fix token reuse, missing expiration or user association, and account changes made before a valid token is presented. Then agree on session behavior for both scenarios, notifications, and normal login after a reset. Include the current-password check in the separate flow for changing a password within an active session.

This plan covers the recovery rules listed here, but it does not establish the security of the application as a whole. These recommendations also do not define a universal link expiration period in minutes. To review your implementation, you can request a free website or web-product audit and include the password reset flow in the discussion of testing scope.

Sources and documentation

  1. Forgot Password Cheat Sheet
  2. Authentication Cheat Sheet
  3. Session Management Cheat Sheet
CheckMyApp

Check your application’s security.

Enter your web application address and email. Get a free preliminary report and choose the depth of analysis.

Check for free