Why is Salt Stored with Password?

May 4, 2009 at 5:25 AM
Hi,

   I was wondering why you store the password salt with the password.  Doesn't that defeat the purpose of the salt?

Cheers,
Aeden
May 4, 2009 at 1:45 PM
Edited May 4, 2009 at 1:52 PM
With an unsalted password, if you had access to the database, you could perform an attack such as this (I am just making up all of the details, such as column names, etc.):
I know that "xyz" is a common password, and I know that the hashed form of that password is "123" (again - just making it up).  So lets see if anyone in the database has that password.  SELECT * FROM [User] WHERE [EncodedPassword] = '123'.  Tada!  I now know which users have password "xyz".
The purpose of salting passwords is to thwart this type of attack.  You mix the salt into the password before the password is encoded.  If you give every user a different salt value, then their encoded passwords will all be different, even if they all have the same password.  So our attacker, who has access to the database, is not helped one bit by the fact that he can see the salt - we have still made his job of figuring out what the passwords are much more difficult.  Instead of just needing to know the hashes of common passwords, he needs to know the hashes of common passwords when combined with all possible values of salt.  So if I use a 512 bit salt, I've made the attacker's job 2^512 times harder.