Optimal bcrypt work factor

Remember that the value is stored in the password: $2a$(2 chars work)$(22 chars salt)(31 chars hash). It is not a fixed value.

If you find the load is too high, just make it so the next time they log in, you crypt to something faster to compute. Similarly, as time goes on and you get better servers, if load isn’t an issue, you can upgrade the strength of their hash when they log in.

The trick is to keep it taking roughly the same amount of time forever into the future along with Moore’s Law. The number is log2, so every time computers double in speed, add 1 to the default number.

Decide how long you want it to take to brute force a user’s password. For some common dictionary word, for instance, your account creation probably already warned them their password was weak. If it’s one of 1000 common words, say, and it takes an attacker 0.1s to test each, that buys them 100s (well, some words are more common…). If a user chose ‘common dictionary word’ + 2 numbers, that’s over two hours. If your password database is compromised, and the attacker can only get a few hundred passwords a day, you’ve bought most of your users hours or days to safely change their passwords. It’s a matter of buying them time.

http://www.postgresql.org/docs/8.3/static/pgcrypto.html has some times for cracking passwords for you to consider. Of course, the passwords they list there are random letters. Dictionary words… Practically speaking you can’t save the guy whose password is 12345.

Leave a Comment