How to Upgrade Password Hashes at Login and Handle Inactive Accounts
You can gradually increase the hashing cost of stored passwords by upgrading the hash after each user's next successful login. But this process alone will not cover accounts whose owners never return. Developers and product owners therefore need two coordinated decisions: how to upgrade active accounts and what to do with the old hashes that remain. This article covers the transition process, performance testing, and situations that require a password reset.
Upgrade the hash after successfully verifying the password
A common way to increase hashing cost is to wait for successful authentication, then hash the submitted password again using the new cost parameter. To verify a password against its stored hash, OWASP recommends using a secure function provided by the language or framework wherever possible. Successful verification must precede the upgrade.
This is the trust boundary: submitting a password does not yet establish permission to change stored account data. Keep verification and the subsequent hash upgrade explicitly separate in the project. During review, a developer should be able to see which condition permits the transition to the new cost and what happens if verification fails.
Plan for old and new hashes to coexist
When hashes are upgraded at login, the database will contain hashes with different computational costs at the same time. This is an expected part of the transition. If a user never signs in again, their hash may remain unchanged. Enabling upgrades during authentication therefore does not mean that migration is complete for every account.
An explicitly fictional example: the team behind a service called Notebook decides to increase its hashing cost. Anna signs in successfully, and the application recalculates her hash using the new parameter. Boris has not used the service for a long time, so his hash remains unchanged. The team's transition plan should address these remaining records separately, rather than assume every user will return.
Make a separate decision for inactive accounts
Depending on the application, it may be appropriate to delete old hashes and require a password reset when the user next returns. This approach lets you stop storing outdated, less secure hashes. It is a separate product decision: returning users will need to reset their passwords instead of signing in as usual.
For the fictional Notebook service, the team can define in advance which old hashes will be deleted and what flow the owners of those accounts will see. The cited recommendations do not establish a universal inactivity period. Such a period must not be presented as an OWASP requirement: the criteria and timing of the transition need to be defined for your application.
Choose the cost based on measurements
There is no universally optimal hashing cost. It needs to be determined experimentally on the application's servers, taking server performance and the number of users into account. Increasing the cost slows password verification at login, so the choice of parameter should be based on measurements of authentication performance.
Before rollout, define acceptable login times for your product and compare different cost settings. Test ordinary password verification separately from successful logins that also rehash the password. Do not promise users a transition with no effect on speed until you have tested the application's behavior with the selected parameters.
Distinguish cost increases from compromise
If a pepper is compromised, it must be replaced. Changing the pepper requires knowing the user's password, so affected users will need to reset their passwords. Do not automatically apply a routine, gradual cost-increase plan to this situation: the reason for the change and the required actions are different.
OWASP also recommends ensuring that credentials are changed when a password is leaked, compromise is detected, or the authenticator technology changes. At the same time, it recommends avoiding periodic password changes simply on a schedule. Instead, encourage strong passwords and enabling multifactor authentication—MFA.
Test the transition using your own test data
Prepare fictional accounts with old and new hashing costs, along with an account whose old hash has been deleted and for which a reset is required. Use only your own test data. This set will let you check the main transition paths before changing real accounts.
- Confirm that a successful login using the old parameter upgrades the hash.
- Check that an incorrect password does not trigger an upgrade of the stored hash.
- Test login with an already upgraded hash and the intended reset flow after an old hash is deleted.
- Measure password verification time and login time with rehashing using the selected parameters.
Set priorities and state the limitations
First, separate cases of compromise that require credential changes from planned cost increases. Then check the password comparison function, choose the cost based on measurements, and agree on how to handle the remaining old hashes. Document the criterion for completing the transition: a working upgrade at login is not enough if some users never return.
These recommendations do not specify a universal hashing cost or a deadline for deleting old hashes, and they do not guarantee the security of the entire authentication system. If you need an implementation review, you can start with a free audit of your website or the web portion of your product to examine the password verification and hash upgrade sequence, the reset flow, and the performance measurements.