1

Instead of creating a separate salt generator for each user, can't I just use their username as a salt? It would be unique for everyone, and achieves the purpose of the salts.

    <?php   
$hashedpass = sha1($username.$password)
 >?

If the username is too short to be used as a salt, I can just add a global string to the username.

$salt =$username.'asdf1234'
$hashedpass = sha1($salt.$password)

Would this be sufficient for security? It still creates a unique salt for each user and prevents rainbow table attacks.

3
  • User names may be the same in a wide enough sample. Commented Jun 21, 2015 at 17:27
  • What happens if they change their username? Commented Jun 21, 2015 at 17:29
  • 1
    PHP has a password_hash function that does everything the right way. Unless you have a very good reason not to, you should use it. Commented Jun 21, 2015 at 17:38

1 Answer 1

1

User names are predictable. I would prefer using random value as a salt. An attacker could begin the generation of precumputed hash table targeting one user (admin?) even before obtaining the hash&salt to crack.

So, you should NOT.

Edit:

The main purpose of having a salt is that rainbow tables are useless. From my point of view, using a guessable value (even with static value added) as salt is bad practice as you allow an attacker to "prepare" the hashes before obtaining your database.

In some scenarios : if you distribute your code and you have a default "admin" account, an attacker will be able to reuse the rainbow table against all the installations of your software.

Other example from @Anti-weakpasswords : Pyrit, "a WPA/WPA2 cracking tool, tool advantage of the WPA/WPA2 protocol using the SSID (username equivalent) as the salt to allow the precomputation of reasonably sized dictionaries against common SSID's - linksys, dlink, 2WIRE047."

7
  • What about mixing up, or adding a string to, the username? Commented Jun 21, 2015 at 17:40
  • You may want to explicitly state that you shouldn't use usernames as passwords. While I understand the risk of precomputation attacks, the OP might not get that from your answer. Commented Jun 21, 2015 at 17:40
  • 1
    @KunalChopra - what is the problem with using the built-in, well-tested functionality of PHP? Commented Jun 21, 2015 at 17:41
  • @r00t - an example you can add to your repertoire is that of pyrit, a WPA/WPA2 cracking tool that took advantage of the WPA/WPA2 protocol using the SSID (username equivalent) as the salt to allow the precomputation of reasonably sized dictionaries against common SSID's - linksys, dlink, 2WIRE047, etc., just like an attacker could precompute an attack again common usernames like jsmith, joesmith, joes, joe.smith, etc. Commented Jun 21, 2015 at 17:53
  • @Anti-weakpasswords - Yes I added it to the answer. Thanks, that's a good "real-life" example.
    – r00t
    Commented Jun 21, 2015 at 17:57

Not the answer you're looking for? Browse other questions tagged .