Password Hashing, BCrypt to SHA1/MD5

bcrypt, encryption, hash, php, sha1

Solution

You best upgrade to `password_hash()`.

As it is likely you are not using PHP 5.5 yet (I assume maybe you are already for testing purposes at this time), you can use the PHP userland implementation of `password_hash()` also written by Ircmaxell for PHP 5.3+.

To upgrade the password hashes on login, you fetch the hash from the database and test first against the new hashing. If it returns FALSE, you test against the old hashing. If that returns TRUE, you re-hash the password with the new new hashing and store it back into the database.

Combining or chaining multiple hashes after each other - and I fear I read that in your question - is a total stupidity you should never consider. Hash algorithms are not compatible to each other and using a hash on a hash that way is doing it wrong: `sha1(md5($password))` and the like effectively reduce the output space which makes it easier to attack - something you want prevent in the future.

So take the new password hashing API that there is in PHP and sleep well.

Problem

I have been looking at upgrading the password hashing security of one of my applications as I have been reading up about brute force attacks being considerably faster then they used to. Currently I am using `sha1(md5($password))` and I see the benefits of using bcrypt + salt. My question is, Would it be any more secure if I were to do the following: Scenario 1: ``` $password -> sha1 -> bcrypt -> sha1 // This would enable me to keep all existing passwords and just // regenerate all the hashes without waiting for the user to re login ``` Scenario 2: ``` $password -> bcrypt -> sha1 // I would have to add an extra column for the new hash until every // user has logged in but the hash will still be sha1. ``` Would any of these two increase the security of the hash at all? I am no cryptographic master, far from it, I would just like a simple explanation as to if it would work, if not, and why. Thanks EDIT After a little more reading, it seems that bcrypt is favoured because of its slowness in that i makes the cpu/gpu work longer before the hash is generated. In the case of sha1 vs bcrypt, sha1 is roughly 300000 times faster then bcrypt. Which begs the question, if bcrypts advantage is slowness, surely a recursive hashing function which uses sha1 300000 times would be as secure as bcrypt? I made this function as an example: ``` function bsha1($data, $salt) { $hash = $data; for ($i = 0; $i < 300000; ++$i) { $hash = sha1($hash . $salt); } ``` Provide it with a salt and itll return a sha1 hash where every iteration is a hashed hash and salt. This takes approximately the same ammount of time as bcrypt. Would this be as secure?

Original source

Related problems