Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of the "salt" when hashing?

Ok, I’m trying to understand the reason to use salt.

When a user registers I generate a unique salt for him/her that I store in DB. Then I hash it and the password with SHA1. And when he/she is logging in I re-hash it with sha1($salt.$password).

But if someone hacks my database he can see the hashed password AND the salt.

Is that harder to crack than just hashing the password with out salt? I don’t understand …

Sorry if I’m stupid …

like image 516
Krzysztof Avatar asked Dec 10 '09 22:12

Krzysztof


People also ask

What is the purpose of adding a salt to the hashing process of a password?

Salt is a cryptographically secure random string that is added to a password before it's hashed, and the salt should be stored with the hash, making it difficult for an attacker to know the original plaintext without having access to both sources.

Why do we use salt in cryptography?

In cryptography, a salt is random data that is used as an additional input to a one-way function that hashes data, a password or passphrase. Salts are used to safeguard passwords in storage.

What is salting and why is it used?

Salting is simply the addition of a unique, random string of characters known only to the site to each password before it is hashed, typically this “salt” is placed in front of each password. The salt value needs to be stored by the site, which means sometimes sites use the same salt for every password.


2 Answers

If you don't use a salt then an attacker can precompute a password<->hash database offline even before they've broken into your server. Adding a salt massively increases the size of that database, making it harder to perform such an attack.

Also, once they've broken in they can guess a commonly used password, hash it, and then check all of the passwords in the database for a match. With a different salt for each user, they can only attack one password at a time.

There's an article at Wikipedia about salts in cryptography.

like image 88
Mark Byers Avatar answered Sep 20 '22 12:09

Mark Byers


Another intention behind the use of a salt is to make sure two users with the same password won't end up having the same hash in the users table (assuming their salt are not the same). However, the combination of a salt and a password may lead to the same "string" or hash in the end and the hash will be exactly the same, so make sure to use a combination of salt and password where two different combination won't lead to the same hash.

like image 21
Percutio Avatar answered Sep 17 '22 12:09

Percutio