1

I have an existing database with about 1.6 million users in it. Currently the passwords are stored as salted SHA1, I'd like to upgrade them all to salted SHA256.

The approach I've taken so far if to migrate each user as they login, essentially validate their password against the old hash and if it matches create a new stronger hash. This works fine, but it's a slow process.

As far as I can see there is no easy way to shortcut this process. Is there a better way?

ilivewithian
  • 18,642
  • 19
  • 93
  • 158
  • 1
    I would suggest swapping over to a more future-proof hashing, like bcrypt, more info here: http://stackoverflow.com/a/10963468/1217408 – TheZ Aug 17 '12 at 19:44
  • What's wrong with your approach. The amount of extra time this process takes for each login is pretty trivial and is distributed over a relatively large period of time (I'm guessing that not everyone tries to log in at once). Is there a reason you need everyone to be on the new hashes immediately? Salted SHA1 hashes are pretty secure, so I can't imagine that there is a huge business case for rushing the process. – Ben D Aug 17 '12 at 19:50

2 Answers2

1

Unless you stored the original plaintext passwords somewhere, you cannot "upgrade" hashes. The text that got hashed is destroyed, and you can't simply "un-sh1" to get it back. Your method is probably the only practical method, unless you want to bulk-generate new sha256-based pws for your users and email them the new one.

Marc B
  • 340,537
  • 37
  • 382
  • 468
1

What you describe is an appropriate and legitimate method of migrating users from a weaker/older hash algorithm to a stronger/newer hash algorithm. I have successfully implemented this technique in multiple situations. Trying to migrate everyone at once is a horrible UX idea and then you run into the problem of needing to mail out passwords, which is a bad idea for multiple reasons, both security and UX.

I would suggest that since you are undertaking such an effort now, that you consider using a different algorithm than salted SHA-256. Salted SHA-512 offers a higher level of security, and implementing a scheme where you stretch the hash is even better (do some high number of iterations of SHA-512 - starting with the password+salt of course). Or, you can take advantage of an algorithm already specifically designed for password hashing such as bcrypt, scrypt, or PBKDF2.