Answer the question
In order to leave comments, you need to log in
What is the safest way to store user passwords in a database (hashing, bcrypt, salt, pepper)?
Correct me if I'm wrong, but as far as I understand, if pepper is not used, then by far the optimal solution is bcrypt($password)
(random salt, cost=10). This will only use the first 72 characters of the password, which is acceptable. Possible variations - scrypt($password)
if it is likely that they will break seriously on special hardware, or sha256($password . $salt)
if there is a danger that using bcrypt can lead to a DoS attack on your service due to the lack of adequate protection against password brute force.
But with pepper, everything is not so clear. It should be large enough that simply adding it to the password will greatly reduce the number of password characters used. To avoid this, you need to use a combination of bcrypt and HMAC, and here there are options, the difference between which from the point of view of cryptography is not clear to me:
bcrypt(hmac_sha256($pepper, $password))
hmac_sha256($pepper, bcrypt($password))
Which of these options is better? hmac_sha256($password, $pepper)
but it seems to me that it is more logical to pass pepper as the first parameter (as a key): hmac_sha256($pepper, $password)
Is there any difference between these options in terms of cryptography? Answer the question
In order to leave comments, you need to log in
Apparently, instead of HMAC, it is more correct to use encryption with any standard algorithm using IV: encrypt_aes_cbc($pepper, bcrypt($password))
There are several reasons:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question