I need to implement some hashing scheme for an open-source project. This is what I currently have and I'd like to hear whether this is secure enough -

The password is hashed using PBKDF2-SHA256 (which I prefer over bcrypt simply because OpenSSL supports it natively) with 2048 iterations.

The salt is actually a concatenation of two strings - the first one is unique and stored in the DB along with the password in plaintext. The second one is shared and stored in plaintext in the program's configuration file. My logic is that this will prevent brute forcing passwords if an attacker gains access to the DB but not to the server's filesystem.

Is this secure? Also how long should each part of the two salt strings be? 16+16 bytes? 32+32 bytes?

Thank you.

  • ... how long should each part of the two salt strings be? 16+16 bytes? 32+32 bytes?" - please don't confuse bytes and characters. Strings consist of characters, not bytes. Strings are usually text only while bytes are binary data. One random byte means 8 random bit. The meaning of one random character depends on the actually characters allowed. For the common setting of only alphanumeric this is around 64 different values only, i.e. 6 bit of randomness and not 8 bit like in a binary byte. Commented Apr 17, 2021 at 12:23

1 Answer 1


That second part of the salt you are talking about actually has its own name - it's called a pepper. And as long as the real salt itself is always unique for each password, adding a pepper doesn't decrease security in any way (it arguably increases it in some scenarios).

Regarding the length of the salt, 16 random bytes* each will be more than enough. Since 16 random bytes is 128 bits of entropy, you can be sure there is practically no chance of your salt ever repeating for more than one password.

*Note that 16 random bytes means 16 random bytes of binary data, not a 16 character string. See Steffen Ullrich's comment

  • "Since 16 random bytes is 128 bits of entropy" - while this is true if actually binary data are used, this is not true if character strings are used, as seems to be in the question. In this case it would likely be about 96 bits of entropy only, i.e. 6 bit for each byte if this byte is only used to store an alphanumeric ASCII character. Commented Apr 17, 2021 at 12:26
  • @SteffenUllrich Right, I missed the word "string" in the question. I'll add a note.
    – nobody
    Commented Apr 17, 2021 at 12:30

You must log in to answer this question.

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