I'm curious about hashing, because normal hashing is static, it means that a string that gets hashed will always be the same (except for using salt). Because of that situation, there are many websites that are able to "crack" a hash by comparing it to hashes in its database.

So I'm curious how much longer regular hashing will be useful? Because soon sites could crack almost any hash with their huge data structure. I know that there are many bots that spam their database by adding many hashes into their databases including the plain text. What will be the alternative to regular hashing?

  • So, do you mean, "how long before every possible string is mapped to its hash along with all possible salts?" ? That's going to be an impossibly long time. Even you constrain it to MD5. Once you add in all the other types of hashes, I think you'd be waiting until the heat death of the universe before it would all get mapped. – schroeder Oct 7 '20 at 22:32
  • Let us continue this discussion in chat. – schroeder Oct 8 '20 at 17:52
  • It turns out that the OP really did mean "any hashing algorithm" and not MD5. Edits reverted. – schroeder Oct 8 '20 at 18:03

Note: This answer was written under the assumption that the question was "When will MD5 specifically not be useful anymore?". For an answer about when hashing algorithms in general will not be useful anymore, please see mti2935's answer.

MD5 is already not useful for passwords.

MD5 was never made to be used to store passwords. That was never its intended purpose, it was just misappropriated for it. Imagine a carpenter driving a nail into a wood by hitting it with the grip of a screwdriver - it works, but it has some disadvantages that could be alleviated by the use of correct tools.

What flaws does MD5 have?

MD5 was originally designed to be a message-digest function, but it has since been demonstrated numerous times that MD5 is not fit for that purpose. Back in 1996, attacks on MD5 have been described. 2004 researchers Xiaoyun Wang & Hongbo Yu demonstrated that MD5 is not collision-resistant, and shortly after an improved attack was described. As the years passed, more and more flaws were found in MD5.

The Wikipedia article goes in-depth on the other security flaws, in case you wish to go down the rabbit hole yourself.

What can MD5 be used for still?

MD5 can still be used as a checksum if you want to ensure that data has not been accidentally modified (e.g. by a transmission error). So calculating a checksum locally, then uploading a file and then calculating a checksum remotely and comparing the two is certainly still a valid application for MD5. Should it be used? Eh...probably not. SHA-1 is faster by a little bit in my testing (MD5 took 2750 ms to hash an 1 GiB file, and SHA-1 took 2550 ms). But if you are on a system where only MD5 is available, don't feel bad for using it to check if two files are the same - as long as you don't expect an attacker to have manipulated them.

Then what should you use to store passwords?

The appropriate tool for the job is a tool that was designed for the job. Just like how you don't hammer in a nail with a screwdriver and don't drive a screw with a hammer, you don't store password hashes using something not made to store password hashes.

In this case, OWASP recommends the following algorithms as by 2020:

  • Argon2id
  • PBKDF2
  • bcrypt

I recall scrypt used to be on that list, but I don't know why it has been removed. What these algorithms have in common is that they have a variable work-factor. That means you as the server owner can define how much work needs to be put in for passwords. This means crackers will get magnitudes worse performance, which makes cracking your hashes a lot less desirable.

  • 1
    And, Crytographically more interestingly MD5 has a pre-image attack that is faster than the generic pre-image attack. – kelalaka Oct 8 '20 at 12:36
  • Do you know why scrypt out in OWASP recommendation? Note: feel to free add my arguments. – kelalaka Oct 8 '20 at 12:59
  • It turns out that MD5 was just an "example" and the OP wanted to know about all hashing algorithms. – schroeder Oct 8 '20 at 18:04
  • @schroeder sigh It's all to tiresome – MechMK1 Oct 8 '20 at 18:19
  • 1
    @schroeder I looked at the chat between you and OP and...my point stands, it's all so tiresome. – MechMK1 Oct 8 '20 at 18:23

This is not likely to happen anytime soon - at least not for a modern hash function like SHA256. There are 2^256 possible outcomes of a SHA256 hash function. In base 10, that's 10^77, on in other words, a '1' followed by 77 zeroes. It's a huge number. By comparison, our universe is 'only' 13 * 10^9 years old. A database that stored every possible output of the sha256 hash function would be so large, there would not be enough disk space on the entire planet to store it.


Not the answer you're looking for? Browse other questions tagged or ask your own question.