1

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?

6
  • My question; why? Commented Oct 25, 2016 at 10:00
  • 4
  • @AdamSitemap because lets say if someone has a list of hashes for all the dictionary keywords. and any of my password is from the dictionary then they can easily find the password. guide me if I am wrong. Commented Oct 25, 2016 at 10:10
  • 1
    Here you have a good answer: stackoverflow.com/a/348140/3623003
    – Vini7
    Commented Oct 25, 2016 at 10:33
  • 1
    @UmairAfzal I can see where you are coming from but it is easy for the bad people to mitigate. The standard way of doing what you want is using a salt (see my answer below) say you have 3 users, 2 users use "abc" as their password and the other uses "abcd". the bad people use a bruit force (a, b,c...aa,ab,ac) so with SHA-2->MD5 they know 2 uesers use the same password, then calculate a to abc and find their first 2 passwords and carry on to abcd and find the 3rd. 1/2 Commented Oct 25, 2016 at 10:36

2 Answers 2

0

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.

3
  • "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 ? Commented 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 Commented 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
    Commented Oct 25, 2016 at 12:17
0

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

PROBLEM WITH MD5 BEFORE SHA2

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 .