0

I've been reading up on OWASP 10 and I came across the best practice to store information. Salted hashing. Where you generate one random salt for every password and combing it and hash it and store it. My doubt is, if the salt is generated randomly how the password be authenticated when the user types it? Is the salt saved along with the user name? If so, this practice is still vulnerable. OR how do they do it?

Sujith
  • 3
  • 4

1 Answers1

0

The salt is saved along with the user name. Salts are not secret. The point of a salt is to ensure that if two people have the same password, they won't have the same hashed password. This prevents pre-computed hash attacks (rainbow tables), and prevents leaking that two users in a database have the same password.

While per-user random salts are ideal, the benefits of salting can also be achieved with deterministic, but unique, salts. For example, you can use some fixed string for your database and join that with the userid (com.example.mygreatsystem:user1@example.com) and use that as the salt. Since it's unique to every user (not just within this system, but globally), it achieves the same goals as a random salt without requiring an extra database lookup. Like with random salts, this scheme does not need to be secret. The important part of a salt is it be unique. But when practical, a per-user random salt of sufficient length (typically 8 random bytes), stored with the user record, is best practice.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • Thanks for explaining. My doubt is that if salts aren't a secret and a hacker gets hold of the salt as well the username and password list, it would be easy for him to crack the passwords right? – Sujith Sep 21 '20 at 13:00
  • No, that's the point of a salt. The salt prevents pre-computation of the hashes, so the attacker has to break one password at a time. There is no efficient way to reverse the hash, so they must guess many passwords. If you only SHA-2 the password+hash, the attacker can reasonably break a very weak password, but if you use PBKDF2 (or another key stretcher) as your hash, only incredibly weak passwords would be vulnerable, and PBKDF2 can be tuned to make guessing as slow as you like. – Rob Napier Sep 21 '20 at 13:42