📚 Encyclopedia

Security & Cryptography · updated 2026-10-26

Migrating legacy password hashes to bcrypt on login

passwordsbcryptphppassword_hashmigrationrollback

Old apps often store sha256(password + salt). You cannot convert those to bcrypt in bulk because you do not have the passwords, but you can upgrade each account the next time its owner logs in. TLDR did this in v1.31.0 (July 2026). It works well; its one sharp edge is that it is a one-way migration, which changes how you are allowed to roll back.

The opportunistic upgrade

function passwordMatches(array $row, string $pw): bool {
    if ($row['pass_salt'] === '') {                       // already bcrypt
        return password_verify($pw, $row['password']);
    }
    $legacy = hash('sha256', $pw . $row['pass_salt']);
    return hash_equals($row['password'], $legacy);         // constant-time
}
// on successful login with a legacy row:
//   store password_hash($pw, PASSWORD_DEFAULT) in the hash column and set pass_salt to ''

The one-way door

After the deploy, every user who logs in gets a bcrypt hash. The previous API version only knows sha256, so rolling the API back locks those users out. Treat any auth-storage migration as a point you cannot blind-rollback past: fix forward instead, or ship the rollback build with the new verification code. Record such points next to the deploy instructions.

Change-password details

Change notifications and testing

See also

Linked from

Sources: tldr memory (release-v1.31.0-audit, feature-change-password), post #1690