Is it a bad idea to use an email address as the salt for a password?
-
What length do you guys recommend a salt should be? – Starlin Sep 24 '10 at 13:20
-
3If it is the only salt using email weaken your users security as multiple web sites using the same system will be crackable using the same rainbow table for a given user. Even if the user took the time to use one password per website / service. – Julien Roncaglia Sep 24 '10 at 13:40
-
Each bit of salt doubles the amount of computation or storage for an attacker that attempts to brute-force-crack the passwords of all users. For known salts (such as login names) however, effort only increases when the attacker targets a particular user as he cannot reuse the results for a user with a different salt. – Arc Sep 24 '10 at 14:44
-
@VirtualBlackFox But salts aren't intended to protect a single user from targeted attack, they're intended to protect an large group of users from simultaneous attack. – Tyler McHenry Sep 24 '10 at 15:03
-
@Tyler yes that's what they are intended for. They protect multiple users of the same site from simultaneous attack. But the fact that they are independent between websites also protect one user across multiple sites from simultaneous attack. Losing this property that protect against another attack vector is a bad idea especially as the computational complexity is similar. – Julien Roncaglia Sep 24 '10 at 15:23
-
Regarding what they are intended for, using incremental values [0, 1, 2, ...] for salts also protect a large group of users from simultaneous attack. But the fact that the salts as a series are predictable even if the salt for one user isn't make this a worse solution (same as with the email) and for the same reason multiple web sites will be crackable using the same set of rainbow tables. – Julien Roncaglia Sep 24 '10 at 15:26
-
I see a minor advantage for doing this (hashing password+email+moreSalt): if a hacker has database write access and knows one user's password, they cannot copy a hash from that account to any other. However, if they can edit something like your hashed password fields I think you're in trouble. – Tom Anderson Apr 22 '22 at 02:18
6 Answers
EDIT:
Let me refer you to this answer on Security StackExchange which explains a lot of details about password hashing and key derivation.
Bottom line: Use a secure established password hashing scheme that is somehow resource-intensive to protect against brute-force attacks, but limit the number of permitted invocations to prevent denial-of-service (DoS) attacks.
If your language library has a function for it, verify on upgrades that it does what it is supposed to do, especially if it's PHP.
The answer below is left for historical reasons.
You could use the user's login name as a salt which might be less likely to change than an e-mail address (EDIT: 0xA3 correctly pointed out, this is less secure than using the e-mail address because login names tend to be easier to guess, and some are quite commonly used such that rainbow tables may already exist for them, or could be reused for other sites).
Alternatively, have a database column where you save the salt for the password.
But then, you could as well use a random user-specific salt just as well which is harder to guess.
For better security, you could use two salts: A user-specific one and a system-wide one (concat them, then hash the salts with the password).
By the way, simple concatenation of salt and passwords might be less secure than using HMAC. In PHP 5, there's the hash_hmac()
function you can use for this:
$salt = $systemSalt.$userSalt;
hash_hmac('sha1', $password, $salt);
EDIT: Rationale for a system-wide salt: It can and should be stored outside the database (but back it up. You won't be able to authenticate your users if you lose it). If an attacker somehow gets to read your database records, he still cannot effectively crack your password hashes until he knows the system-wide salt.
EDIT (slightly off-topic):
A further note on the security of password hashes: You might also want to read Why do salts make dictionary attacks 'impossible'? on hashing multiple times for additional protection against brute-forcing and rainbow table attacks (though I think that repeated hashing may introduce additional opportunities for denial-of-service attacks unless you limit the number of login attempts per time).
NOTE
Considering the rise of multi-purpose multi-core systems (graphics cards, programmable micro-controllers etc.), it may be worth using algorithms with high computation effort along with salts to counter brute-force cracking, e.g. using multiple hashing like PBKDF2. However, you should limit the number of authentication attempts per time unit to prevent DDoS attacks.
One more thing: Another main rationale for using a "custom" hashing built on widely-used standards rather than a widely-used pre-built function was PHP itself which has proven itself to be not trustworthy at all when it comes to implementing security-related stuff, be it the not-so-random random number generators or a crypt()
function that does not work at all under certain circumstances, thereby totally bypassing any benefits that a compute- or memory-intensive password hashing function ought to bring.
Due to their deterministic outcomes, simple hash functions are more likely to be tested properly than the outputs of a key derivation function, but your mileage may vary.
-
-
1Using the login name as a salt is even worse than using the email. It makes pre-computing your rainbow tables easier because there are user names you will find on almost any site. Besides that point I like your approach with using two salts and it would be +1. – Dirk Vollmar Sep 24 '10 at 13:42
-
I'm not a cryptography expert, however there are 3 things in particular that strike me as possibles issues with this suggestion.
- As Mark points out, the email may change, however the salt needs to remain the same for a given password (otherwise you won't be able to check the validity of the password).
- The size of email addresses is variable, and I imagine that it is important that the salt be larger than a certain size.
- Using an email address makes the salt much more predictable, which is usually a bad thing in cryptography.
I don't know if any of these is an issue or not, however the thing about cryptography is that often nobody knows until someone has devised an exploit (and by then its too late) - so my advice would be to err on the side of caution and not use email addresses as salt.

- 84,773
- 49
- 224
- 367
To increase security, it would be better to use a random salt. Email addresses can be found out quite easily, thus reducing the effectiveness of the salt. (Clarified in comments)

- 68,824
- 13
- 156
- 205
-
1The salt is designed to make brute forcing and using a rainbow table more difficult if the database was compromised... so I don't understand your point – Starlin Sep 24 '10 at 13:14
-
The salt is designed to make rainbow tables unusable in the first place. But yes, it can hinder brute force too. Though for the strong password it's negligible. It's better to count that salt has been compromised. And, you know... speaking of such things, while 99% of applications sending passwords as a plain text over net, is funny – Your Common Sense Sep 24 '10 at 13:18
-
1I too don't understand your point keyboardP - Salt is designed to protect against attacks where the attacker already knows what the salt is. – Justin Sep 24 '10 at 13:22
-
-
2Sorry, I should've been clearer. Yes, the salt complexity is irrelevant because dangerous access to that would assume access to the database. However, I personally believe in trying to make security as tight as possible. A lot of sites use the same hashing techniques. Now lets say they all use email addresses as salts. Constructing one rainbow table, regardless of how long it takes, will effectively break the security on multiple databases. It may be unlikely for trivial sites, but is it really that much more work to add a random salt? – keyboardP Sep 24 '10 at 13:35
-
Yeah the same just came to my mind. Nothing bad in slightly better security. Although the rest of site is 1000 times more vulnerable than these hashes... – Your Common Sense Sep 24 '10 at 18:54
-
True, security is only as strong as its weakest link. Still, deciding what constitutes as your salt isn't going to require a massive architectural redesign, so there's no need to fall into unneccessary practice IMO. – keyboardP Sep 24 '10 at 19:19
Like all things security-related, the answer depends on the question, which didn't include information on how secure you want the system to be. The most secure building is one with no windows or doors; it's also the most useless building.
From the highest level: no it's not a bad idea. It's not a great idea either. However, it may be good enough -- or more than good enough -- for your application.
If someone has a rainbow table for a specific email address, are you going to be able to stop them by hashing a password with a random salt? Good hackers take the path of least resistance, which may include getting root access to your system and downloading the salt and user tables. (Are they separately secured?) If so, they have until a password change to match a hash, regardless of the system-enforced consecutively failed login attempt limit or what you chose for salt.
How much more complexity arises from random salt in your application? How determined a hacker are you trying to thwart? What other measures -- maximum consecutive failure lockout, forced password expiration periods, ingress and DoS alerts, firewalls, etc. -- do you have in place? The answer lies somewhere in the convergence between the answers to those questions and maybe others as well.

- 427
- 3
- 6
As others already mentioned, salt should best be random. The purpose of a salt is to prevent rainbow table attacks using pre-computed hash dictionaries.
Assuming an attacker gets to know the hashed passwords and salts from your database, if the salt is "a74kd%$QaU" and the password is "12345", will he be able to crack it using a rainbow table? No, even if the password is weak, the attacker won't have a pre-computed hash dictionary at hand for your random salt.
If you however use a non-random salt like the user id or email it is somewhat more likely that someone already created a rainbow table for that salt, hoping to find a user with username "john" or the email "john.doe@example.com"1
1WPA security for WLANs uses the SSID of the access point as a salt. Too bad, someone already pre-computed hashes for the most frequent SSID names.

- 172,527
- 53
- 255
- 316
-
30xA3, such a coinsidence, I am generating a rainbow table now using the salt "john.doe@example.com". I understand your point, but there isn't a person in the world with rainbow tables with the salt "john.doe@example.com". They take far too long to make and require far too much storage space for someone to make such a table... I am however going to go with a random salt, because I realised that there is a chance in the future that the email may need to be changed. – Starlin Sep 24 '10 at 13:31
-
@Starlin: Email addresses might be better than user names or SSID values, but why make things unnecessarily easier to attack? The SSID rainbow tables from the link in my answer were generated in only 3 days and are only 40GB in size. And this is where another point comes into play: The hashing function needs to be slow. – Dirk Vollmar Sep 24 '10 at 13:40
-
@0xA3: WPA also changes the keys automatically on interval. If the interval is smaller than rainbow table lookup time, you could use a fixed salt just as well. – ssamuel Jan 29 '14 at 02:19
Ophcrack (which is what most attackers would probably use, depending on your encryption function) doesn't contain tables with special characters like '.' or '@' unless you get to the biggest ("extended") tables. So using an email would probably be better than many other salts.

- 11,581
- 11
- 56
- 94
-
This is an interesting observation. If you are genuinely concerned about a rainbow table or brute force attack, using a more complex salt would have some benefit. – Freiheit Sep 24 '10 at 13:36