- Do not use a single pass of any hashing function to store passwords.
- Do not fail to use a random salt in the 8-16 byte range.
Instead, your application has a user is select a keyword/passphrase:
- Generate a cryptographically random 8-16 byte salt
- Use PBKDF2, BCrypt, or SCrypt with said salt and as large an iteration count/work factor as your processors can handle to create a password hash
- If you use PBKDF2 in specific, do not request a larger output than the native hash size (SHA-1 = 20 bytes, SHA-256 is 32 bytes, SHA-384 is 48 bytes, and SHA-512 is 64 bytes), or you increase the comparative advantage an attacker has over you, the defender.
Then in your database, your application stores that user's particular:
- Salt in the clear
- a BINARY(8) or BINARY(16) column
- Iteration count/work factor
- an INT UNSIGNED column
- So you can easily change/upgrade it later
- Resulting password hash
- perhaps a BINARY(20) column for any 20 byte output length PBKDF2-HMAC-SHA-x, or a BINARY(24) for the 192 bits of BCrypt, or BINARY(64) for the native output size of PBKDF2-HMAC-SHA-512
- Alternately, you can Base64 encode the binary output of PBKDF2/BCrypt/SCrypt, but then you must be sure to either use a case sensitive comparison or Base64 decode it after retrieval
- Version of authentication protocol - this would be 1, or perhaps 0.
- a TINYINT UNSIGNED column
- So you can easily change/upgrade it later if you move from this method to NewWellKnownMethod later
When the user wants to authenticate to your system, you:
- Retrieve their version, salt, iteration count/work factor, and resulting hash from the database
- Hash whatever keyword/password they just entered with the salt and iteration count/work factor from the database.
- Compare the result you just got with what was in the database; if they're the same, let them in.
- Advanced: use a constant time compare, so it doesn't just quit trying if the first byte is different, to reduce the vulnerability to timing attacks.
After you've authenticated the user, you'll need to look that user up in some permissions table and determine what they're allowed to do, or use their application level username as a parameter for every query the application executes to ensure they're only retrieving their own data.
Please read How to securely hash passwords?, of which Thomas Porrin's answer is currently the most commonly referred to Stackexchange treatise on password hashing, and certainly the best I've seen so far.