1

I am creating an authentication system that is able to login to the same account with different sets of credentials. I also want to allow users to login with either username or email with the same given password. To make it a little easier, I'm thinking of making the username and email a different record in the database with a different salt thus a different hash. Since this would be the same for all users, a compromised database would let the attacker know that two different hashes are derived from the same password.

Q: Does this knowledge weaken the derived password (even a bit)? Or is it better to use the same salt on the same password for one user (which would just be a copy of hash+salt)?

Note: I understand that storing two hashes with different salts of the same password is perfectly fine – that is why salt is used. But here the attacker gets a hint for the derived password. So https://security.stackexchange.com/a/269416/292328 doesn't answer my question.

1 Answer 1

0

If you were to create two password entries for each account salted by the account representation (user or email), then I would imagine it is a bit weakened.

Instead, just map it before you do your hash check. If the user enters their email address, look it up in your account database and then do the rest with the username. Just make sure you don't accidentally expose that mapping, say in a verbose error message that finds its way to a 5xx HTTP response (which is one of two good reasons to store based on user name/id. The other good reason is that it lets the user change their email without changing anything in your backend other than that map).

1
  • The OP didn't suggest to misuse the name or e-mail address as a cryptographic salt. The question was: If the same password is hashed with different (random) salts, and an attacker knows this, can the attacker exploit some weakness in the algorithm to obtain the password more easily? I'm not aware of any such weakness for modern password hash algorithm like bcrypt, scrypt or Argon2. In fact, if this weakness existed, the algorithm would be completely unsuitable for password hashing.
    – Ja1024
    May 26, 2023 at 11:45

You must log in to answer this question.

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