← Back to blog

Updated 18 November 2026

Upgrade legacy scrypt password hashes during sign in


A password hash upgrade should happen inside the normal sign in path. The application verifies the stored scrypt hash with its existing parameters, accepts the password only when that comparison succeeds, then writes a new Argon2id hash before returning the completed session or the next authentication step. The person keeps the same password. The application avoids a mass reset campaign. Accounts move to the current hashing policy only after the owner proves knowledge of the password, which keeps the migration tied to real authentication rather than a separate data conversion job.

Keep verification and migration in one operation

The important boundary is the successful password check. A background worker cannot turn a scrypt digest into an Argon2id digest because a secure password hash does not reveal the original password. Only the sign in request contains the secret needed to produce the replacement hash. That makes the authentication service the correct owner of the upgrade. It already has the account record, the configured hashing policy, the failure controls, and the transaction that decides whether sign in can continue. Adding a second migration path creates competing rules for credentials and makes failures harder to reason about.

Treat the update as part of the account write that follows verification. Record the new digest only after the old digest matches. Do not change the account when verification fails. Do not log either digest, the supplied password, or the hashing parameters as request data. If the replacement write fails, fail the sign in safely and leave the valid legacy hash intact so the person can try again. A partial upgrade must never destroy the only credential that can still be verified.

Return the right authentication result

A correct first factor does not always mean that sign in is complete. An account can require another factor. The password service should finish the hash replacement before it returns either a completed session result or an MFA challenge. Both outcomes prove that the password was correct, so both are valid upgrade points. The caller must still inspect the returned status and handle the challenge as a successful first factor. It should not read session fields until the result confirms that a session exists.

This ordering also avoids repeated work. If the account requires MFA and the upgrade happens only after the second factor, every abandoned challenge leaves the legacy hash in place. Moving the replacement immediately after password verification means the next attempt uses the current policy even when the earlier challenge expired. The application still creates no session until the required factors finish. Credential modernisation and session creation remain separate decisions with a clear sequence.

Roll out without a flag day

Measure the migration by hash type, not by copying account identifiers into logs. An aggregate count of remaining legacy hashes shows progress. A count of successful upgrades shows whether active accounts are moving. Authentication failure rates should be watched beside those totals because a sudden change can expose a parameter mismatch or an unsupported legacy format. Keep the old verifier available while legacy hashes remain, but do not use it for newly created passwords or password changes.

Inactive accounts may retain the old format for a long time. That is expected in a sign in driven migration. Decide separately whether policy requires those accounts to reset before future access. If so, mark that requirement through normal account state and recovery controls. Do not fabricate a new hash, weaken verification, or treat inactivity as proof that an account can be discarded. The stored credential remains part of the account until an authorised retention or deletion rule says otherwise.

Verify the migration outcome

Exercise four results before relying on the rollout. A correct legacy password should replace the digest and return the normal authentication result. A wrong password should leave the record unchanged. A correct password for an account that requires MFA should replace the digest and return the challenge data without creating a completed session. A database failure during replacement should leave the legacy record usable and return a safe error. Those checks prove the product rule: successful verification moves the credential forward, while every failure preserves account integrity.

Legacy password hash questions

Can a background job convert scrypt hashes to Argon2id?

No. A secure password digest does not reveal the original password. The replacement hash can be created only when the person supplies the correct password and the application verifies it through the normal sign in path.

Should the upgrade happen before MFA completes?

Yes. A valid password completes the first factor, so the application can save the new digest before returning an MFA challenge. It must still wait for the required second factor before creating a completed session.