0

So I was reading through an article about how passwords are salted and hashed through a cryptographic function here, and found out that hashed passwords, along with the plaintext salt values are stored in the database.

Now, I was wondering: if both the hashed passwords and salt values are stored in the database, if hackers can access the database and therefore, access the salt value used to generate the hash for the password, wouldn't it make the salt completely pointless anyway as hackers would already know that they simply have to add the salt value at the end of the password and guess the password as normal?

0

1 Answer 1

-1

No, the benefit of salts does not depend on them being secret.

Salts primarily force an attacker to brute-force each stored hash individually, so that the hashes cannot be attacked all at once. Without salts, the attacker can choose a potential password, calculate its hash and then check whether any of the stored hashes match. If that's the case, they've found the password of the corresponding account(s) -- note there may be multiple matches if users have the same password. In contrast, salted hashes prevent an attacker from reusing their computed hashes. They have to choose a potential password, then choose one of the salts, compute the hash and compare the result with the salted hash from the database. In other words, if there are n salted hashes, the attacker has to perform n hash calculations to try a single password. Without salts, they would only have to do one calculation per guess.

Of course this only slows down an attacker significantly if the hash calculations are computationally expensive. You cannot use general-purpose hash algorithms like SHA-256, SHA-512 etc., because those are designed to be fast, allowing an attacker to calculate billions(!) of hashes per second on consumer graphics card. Salts only make sense in specialized hash algorithms that are purposely expensive like bcrypt or the newer Argon2 family.

There are some secondary benefits of salts:

  • They prevent the use of precomputed lookup tables. Without salts, it's possible to calculate the hashes of different potential passwords prior to a concrete attack, store the results in a table and then use this table for quick lookups in attacks. You can actually google many unsalted hashes, because there's a good chance somebody has already found the corresponding password and put it on the Internet.
  • They hide the fact that multiple accounts share the same password. However, if there are identical passwords, that usually implies the password itself is very simple and can be easily guessed (like a word from the dictionary), so salting doesn't help that much here.

None of those benefits require the salt to be secret. You can use a secret parameter -- often called a pepper -- in addition to salts, but that's an entirely different concept with a different purpose. A pepper forces an attacker to not only gain access to the database but also compromise the target application or server which keeps the pepper.

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