kelektiv / node.bcrypt.js

bcrypt for NodeJs
MIT License
7.43k stars 510 forks source link

Document the upper and lower bounds for the rounds parameter in genSaltSync #898

Open nomuna opened 2 years ago

nomuna commented 2 years ago

Apparently the rounds parameter for the method bcrypt.genSaltSync() has an upper bound of 31. According to the _encodesalt in bcrypt.cc.

/**
 * @param rounds The cost of processing the data. Default 10.
 * @param minor The minor version of bcrypt to use. Either 'a' or 'b'. Default 'b'.
 *
 * @example
 * import * as bcrypt from 'bcrypt';
 * const saltRounds = 10;
 *
 * const salt = bcrypt.genSaltSync(saltRounds);
 */
export declare function genSaltSync(rounds?: number, minor?: "a" | "b"): string;

For higher numbers a cryptic error message is created which misleads people to thinking that they may have passed in an argument of wrong type or format.

Error: Invalid salt. Salt must be in the form of: $Vers$log2(NumRounds)$saltvalue