Upgrading user passwords from salted SHA1 to bcrypt Upgrading user passwords from salted SHA1 to bcrypt codeigniter codeigniter

Upgrading user passwords from salted SHA1 to bcrypt


The whole point of a hash is that you can't recover the original password.

You have three options:

  • Store bcrypt hashes of the SHA1 hashes, then SHA1 hash each password before bcrypting it on every login.
    This may not be a good idea.

  • Upgrade each hash next time that user logs in. (so that you have the plain text to hash)
    This is the best option, but you need to keep your SHA1 hashes and transition code until every single user logs in

  • Reset every user to a random bcrypted password and force them all to use Forgot Password to change it back.
    You probably don't want to do this


  • Add a column to your database that tells the system which hashing algorithm has been used
  • On login, check the credentials as normal
  • If they're using the old one and login is successful - bcrypt the password they entered and update their password and algorithm in the database.


You could create a random password for each user and send out a notification email to everyone with their new password. But this will result in confusion if a user doesn't see the email.

I recommend that you add another db field for the bcrypt value and then create an entry when a user logs in for the first time after the change. You can use either a separate field or delete the old hash to keep track.

When your active users have migrated, feel free to use the random password approach for the rest of your userbase to finish the migration.