Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading user passwords from salted SHA1 to bcrypt

I've been hired to rebuild a actively used application that was built on CodeIgniter 1.7.3 (on a PHP 4.2 server) using Laravel 4 on a new PHP 5.3 server.

The system has about ~500 users whose passwords are encrypted with a salted SHA-1 hash. I'd like to use bcrypt to increase the application's security as well as to integrate with Laravel 4's authentication system.

How would you suggest migrating these users passwords?

like image 417
Nick Avatar asked Oct 03 '13 14:10

Nick


3 Answers

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

like image 125
SLaks Avatar answered Nov 06 '22 07:11

SLaks


  • 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.
like image 28
Jonathon Avatar answered Nov 06 '22 08:11

Jonathon


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.

like image 1
Patrick Avatar answered Nov 06 '22 08:11

Patrick