Salt is a random string that is used to mitigate dictionary attacks.
+-------+------------+-----------------------+
| id | salt | hashed_pw |
+-------+------------+-----------------------+
| user1 | 9060d63fe0 | hash(pass19060d63fe0) |
| user2 | 39b3cdd660 | hash(pass239b3cdd660) |
+-------+------------+-----------------------+
Pepper is a fixed string that is more secret then the salt, and this mitigates brute force attacks on salted passwords.
Is a pepper simply concatenated to the beginning or end of a salted password? Is it concatenated to the salted password, which is then hashed again?
Peppers should not simply be concatenated because it's goal is to make brute forcing impossible. It too must be hashed.
Let's assume password abcd1234
and salt 9060d63fe0
. If those two are hashed with bcrypt
with round 9
, the result will be $2a$09$T.FYSHNRG5W.EiS3ieAU/OqdnNLXtou3yZk98/ZJ0Y7JXAoFlVWKS
.
If somehow hacker brute forces the password and manages to find the value abcd12349060d63fe0
, the hacker will know that the salt value is 9060d63fe0
and the password is abcd1234
because salt is stored on the DB.
But let's assume a pepper is applied. pepper abab4321
, password abcd1234
and salt 9060d63fe0
. If hacker successfully brute forces
and found abab4321abcd12349060d63fe0
, the hacker won't be able to know which part is the pepper and which is the password.
Peppers can be applied before hashing like this:
+-------+------------+-----------------------------+
| id | salt | hashed_pw |
+-------+------------+-----------------------------+
| user1 | 9060d63fe0 | hash(pepperpass19060d63fe0) |
| user2 | 39b3cdd660 | hash(pepperpass239b3cdd660) |
+-------+------------+-----------------------------+
Or after hashing like this
+-------+------------+--------------------------------------+
| id | salt | hashed_pw |
+-------+------------+--------------------------------------+
| user1 | 9060d63fe0 | hash(pepper + hash(pass19060d63fe0)) |
| user2 | 39b3cdd660 | hash(pepper + hash(pass239b3cdd660)) |
+-------+------------+--------------------------------------+