Lets say I have a system in which I save the user's passwords using SHA-2. Now I was just wondering would it be a good approach if I take the MD5 hash of the password and then compute SHA-2 for the resultant MD5 hash? Are there any chances of duplications?


2 Answers 2


There is always a chances of duplication's but most of the time the chance is fairly low (but higher than you would think, look at the birthday 'paradox')

Hashing twice will not give huge amounts of extra security, it is the security of hash 1 + security of hash 2.

To increase the security of password hashes you should salt them, this is give each password an individual random string to be appended to the password each time it is hashed, this will remove the threat of a pre-calculated table (rainbow table) revealing the passwords.

As mentioned in the security now podcast, there is nothing wrong with hashing passwords multiple times, actually it is encouraged because if you want to change the hash that your passwords are encrypted with, you dont have to wait for the password to be entered again to hash it with the new hash, you can hash all the old hashes with the new hash. This gives everyone the security of the new hash immediately.

I would also like to point out that MD5 and SHA-2 are bad hash functions for passwords. Password hash functions should be 'slow' and MD5 was designed to be fast (I don't know about SHA-2), you should use functions like Argon2, bcrypt, scrypt, or PBKDF2 which are really hard to speed up.

  • "his is give each password an individual random string to be appended to the password each time it is hashed" So if the string we are adding is random Then how are we going to remove it ? Oct 25, 2016 at 10:07
  • 1
    you dont, your store it with the hash, then when the user enters their password you append their input with your salt, put the result through the hash function which should match the hash you have stored if the user input is the same both times Oct 25, 2016 at 10:09
  • I don't see anyone explaining the downvotes: you are suggesting various ways of re-inventing bcrypt (or scrypt or pbkdf2 or whichever flavor you like). Use one of those, not something self-invented. See: How to securely hash passwords?
    – Luc
    Oct 25, 2016 at 12:17

It will not have any benefit, as the purpose of hashing is to map data of arbitrary size to data of fixed size uniquely and irreversibly


There are a lot of examples of MD5 collisions so your two pieces of data, s1 and s2, may lead to the same MD5 hash, which can lead to the same SHA-2 output.

I don't think this is what you want.

Not the answer you're looking for? Browse other questions tagged .