Take the 2-minute tour ×

What is "salt" when relating to MYSQL sha1? I have no idea what salt is when relating to sha1 password encryptions? Can someone please explain what it is?

share|improve this question
add comment

3 Answers

up vote 8 down vote accepted

A salt is a value that is added to a password (or other secret) which you want to hash one way. This means it could be before, after, or somewhere inside the password, as long as its position and value is consistent for a given supplied password.

What this does is it mitigates dictionary attacks - basically dictionaries of common passwords pre-hashed with no salt - from being used to "guess" a one way password as long as the attacker does not know the hash. If every password has a different hash then it makes it very difficult for an attacker to create a dictionary optimized for cracking your passwords (they would need a dictionary for each separate salt and they would also need to know where the salt was placed in each password).

Of course for all of this to be applicable an attacker must have the hashes of your passwords in the first place. This has nothing to do with attacking passwords by guessing them through some input prompt.

Regarding MySQL specifically if you provide a salt when hashing a password, make sure you record what that salt was somewhere. Then when a user attempts authentication you combine that recorded salt value with the password (during the call to crypt for example) and if the resulting hash matches then they have entered the correct password. (Note that at no time is the hashing of a password reversed; thus one way.)

share|improve this answer
add comment

salt is nothing but an string you attach to the password, either as a constant or through a algorithm

which makes it harder for anyone who breached your security and gain access to your stored password, which in return makes in next to impossible for him to use rainbow dictionaries to unlock what the real password is, which in a hacker point of view can be usefull since alot of people use the same password in alot of diffrent sites

$salt = "this is a salt";
$password = 'this is an password';
$hash = sha1($salt.$password);

That's how you basically could salt a password

share|improve this answer
What type of string? –  Noah R Dec 4 '10 at 3:08
@Noah: "0e7eb"​ –  Ignacio Vazquez-Abrams Dec 4 '10 at 3:12
@Breezer: Incorrect; you can't extract it from the hash. It is stored separately though, along with the algorithm used and resultant hash. –  Ignacio Vazquez-Abrams Dec 4 '10 at 3:14
a salt must always be random. if you use a constant, it is a key instead of a salt. –  Jacco Dec 27 '10 at 9:11
@Jacco: Not necessarily random, just not constant. :) –  Sasha Chedygov Dec 27 '10 at 10:19
show 13 more comments

A salt is appended to the plaintext (or vice versa) before hashing in order to make dictionary lookups more expensive.

share|improve this answer
COuld you give me an example? –  Noah R Dec 4 '10 at 3:08
+1 - right. For example, it means that an attacker who has access to a bunch of hashed passwords can't just SHA1-hash a dictionary once and compare it against all the passwords in bulk; because of the salt, the hashing has to be re-done (with correct salt) for each password. –  David Gelhar Dec 4 '10 at 3:12
add comment

Your Answer


