For hashing passwords in a database, i would like to add a pepper to the hash function. Of course this pepper will be additionally to the unique salt.
The reason why i want to add a pepper is, that it prevents a dictionary attack, in case that the attacker has only access to the database, but not to the server (typical for Sql-Injection). In my opinion this is better than a hash without pepper, even if the pepper is only hardcoded (to avoid code complexity).
Now i wonder, how the pepper should be applied correctly, is it correct to just append the pepper to the password before hashing?
1. Concatenating password and pepper
$passwordHash = bcrypt($password . $pepper, $salt);
A reason against this could be, that passwords bigger than the bcrypt limit (55 characters) will not get the pepper, although passwords of this length are propably not in a dictionary anyway. Because of this limit, the pepper is added after the password and not before. Another reason could be, that if the attacker knows the pepper, he also knows the ending of all our peppered passwords.
2. Combine password and pepper with hash
$passwordHash = bcrypt(hash('sha256', $password . $pepper), $salt);
So we could use a hash function to combine password and pepper, before hashing. Is it appropriate to use sha256, or which hash function would be ideal, when we want to use bcrypt afterwards?
3. Combine password and pepper with hmac
$passwordHash = bcrypt(hash_hmac('sha256', $password, $pepper), $salt);
Often a hmac is the recommended solution, is there any advantage over using SHA256 directly? Since we only want to combine password and pepper, and the security comes later from the bcrypt, i cannot see any apparent advantage.
Any helpful hints are much appreciated.