However, MD5 is not a suitable algorithm for hashing passwords because although the digests look like gibberish, there are now tools that can use the digest to reverse-engineer the password. To hash passwords, we need to use a special class of hash functions called cryptographic hash functions, which have the following special properties:
- Deterministic: Given the same message, they will always produce the same digest.
- One-way: The message, or a part of the message, cannot be reverse-engineered from the digest. The only way to obtain the original message from the hash is to try every possible value for the message to see if the generated hash matches.
- Exhibits the avalanche effect: A small change in the message would produce a drastically different digest. This prevents a cryptoanalyst from finding patterns between hashes and narrowing down the possible combinations for the message.
- Collision-resistant: Two different messages should produce two different digests. The chance of two different messages producing the same digest is minuscule.
- Slow: This may seem counterintuitive, but when hashing is used for security, a slower algorithm discourages brute-force attacks. Here's a case in point: a hashing function that takes 1 ms to execute can produce 1 billion hashes in 11.5 days. A hashing function that takes 40 ms to execute can produce 1 billion hashes in 463 days, which is a significantly longer time. However, to a normal user, the difference between 1 ms and 40 ms is negligible. In other words, we want our algorithm to be slow for an attacker, but not for legitimate users.
- Robust: It must stand the test of time.