Course contentsShow
← Security
Lesson 692 of 3,05215. Web Security - Authentication and SessionsFree lesson

Upgrading Legacy Password Storage Systems

Explore strategies for migrating from weak to strong hashing without forcing mass password resets.

Upgrading Legacy Password Storage Systems

What you'll learn: How to migrate from weak password hashing (like plain text or MD5) to strong algorithms (bcrypt, scrypt, Argon2) without forcing every user to reset their password immediately.

The Challenge

You've inherited a system storing passwords with MD5 or SHA-256—fast hashes that are vulnerable to rainbow tables and brute-force attacks. The right solution is Argon2 or bcrypt, but you can't just rehash everything: you don't have the plain-text passwords anymore!

The Incremental Migration Strategy

The clever approach is lazy migration—upgrading passwords gradually as users log in:

  1. Wrap the old hash: When a user successfully authenticates (proving they know their password), immediately rehash their password with your new algorithm (bcrypt/Argon2) and store that instead
  2. Hybrid storage: Keep a flag indicating which algorithm was used for each password
  3. Dual-path verification: Check the algorithm flag during login—verify old hashes with the old method, new hashes with the new method
  4. One-way transition: Once rehashed, passwords never go back to the weak algorithm

The Double-Hash Technique

For accounts that haven't logged in yet, you can hash the old hash with the new algorithm. If the old database stored md5(password), store bcrypt(md5(password)) for all existing records. It's not perfect (still limited by MD5's weaknesses), but it's vastly better than leaving them in MD5, and requires no user action.

Why This Works

Think of it like renovating a bridge while traffic flows: you can't close it entirely, but you can upgrade sections as cars pass through. Users naturally authenticate themselves by providing their password, giving you the opportunity to upgrade their security transparently.

Key Takeaway: Lazy migration lets you upgrade from weak to strong password hashing gradually—rehashing passwords opportunistically during login—without forcing mass resets or leaving your system vulnerable during a long transition period.