0

I heard it was good practice to have each user have a unique salt, when I'm hashing a user's password with a salt. My question is, can I make my salt a hash of the user's username? Ex.

$username_hash = hash($username);
$pwd_hash = hash($username_hash + $password);

Would something like that be considered acceptable? And more importantly, secure?

Edit:

I know I could do

    $pwd_hash = hash($username + $password);

But if I do that it doesn't protect from rainbow tables, although a hash of the username would.

Alex Jone
  • 103
  • 3

1 Answers1

3

No.

Remember that people tend to reuse passwords from service to service. If two systems use your scheme and someone uses the same username and password on both systems, then they will end up with the same hash in both cases.

Salts aren't secret, and technically the randomness requirement on them isn't as strong as what is required for cryptographic keys, it is best to generate them the same what that you would generate keys just to avoid this and other sorts of mistakes that people make when creating salts.

Jeffrey Goldberg
  • 6,605
  • 18
  • 21