node.bcrypt.js icon indicating copy to clipboard operation
node.bcrypt.js copied to clipboard

Questions about rounds and the interface

Open cl-aaron opened this issue 12 years ago • 2 comments

Hey, I'd like to use bcrypt for password hashing but I'm a bit confused about the interface. As I understand it bcrypt is an algorithm with an adjustable work factor which will affect the time it take to hash a password. However, in the documentation it seems the only place to change the number of rounds is on the genSalt functions.

Is the salt somehow telling the hash algorithm how many rounds to complete?

cl-aaron avatar Oct 03 '14 19:10 cl-aaron

Yes. As part of the algorithm, the salt has the number of rounds in it.

> bcrypt.genSaltSync(10);
'$2a$10$GMgbC9H56jqamgQ/jh4kAO'

So, in this example, the 2a defines the version of the algorithm, and the 10 defines the work factor, with the rest being the generated salt.

ncb000gt avatar Oct 03 '14 20:10 ncb000gt

Awesome, thanks!

cl-aaron avatar Oct 03 '14 20:10 cl-aaron