I am currently working on a system where I need to store the hashed password.
I am using cryptographically secure pseudo-random number generator(CSPRNG) for generating the salt. I am using the PBKDF2 for hashing the password appended with the salt which finally will be stored in the database.
What I am not getting is why do I even need to store the salt along with the hashed password in the database. I do understand the purpose of the salt. It significantly reduces the chance of a successful rainbow and lookup attacks. Also users with same password will have different hashes stored in the database.
So where is the need comes for storing the salt in the database?
UPDATE:
I should have mentioned this earlier, but that time it didnt click me. The
passwordhere is never going to be provided by the user. It is for our internal purpose. We just need it to be generated for the first time user comes to our website, and later on we will just send thisHashedpassword in the response.
You already understand at this point that if you use Password1 on its own (without a salt) then every time you hash it, you will get the exact same result. Now, let's pretend you have 1000 users and of those 1000, 25 of them use the same password. Those 25 hashes are going to be exactly the same. Once an attacker gains access to your database and finds the hash 70ccd9007338d6d81dd3b6271621b9cf9a97ea00 translates to Password1, they will have gained access to 25 people's accounts in no time at all. This means a rainbow table attack will allow him to access more accounts, faster.
By appending a salt to the value of Password1 you are going to dramatically change the hash. Each user should have their own salt. This means that even if you have all 1000 of your users using Password1, all 1000 hashes will be completely different. In real real world, this means that the 25 of your 1000 users who have the same exact password will all have different hashes. However, it also means an attacker will have to run an attack on one password at a time, rather than just rainbow tabling the hashes and hoping for the best.
Without the salt, you won't be able to recreate the hash when the user enters their password - meaning the user can never log in again and access their account. By storing the password, you can allow the user to enter their password and then you run a lookup on their account, append the salt to their input, and hash the entire thing; if it matches the hash stored in the database you've got the right password! If you never store this salt, you can never recreate the hash!
I hope this explains a little better, and as always if you have any comments feel free to ask
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With