bcrypt-small
bcrypt-small provides functions to asynchronously create and verify password hashes.
Passwords are encoded as UTF-8, cannot contain null bytes, and must be no longer than 72 bytes; an error is produced if these conditions are not met.
Example
const bcrypt = ; bcrypthash'password' 12 { if error console; return; bcrypt; bcrypt; console; // 12};
Functions returning built-in promises are provided by bcrypt-small/promises
:
const bcrypt = ; async { const hash = await bcrypthash'password' 12; console; // true console; // false console; // 12};
API
bcrypt.hash(password, logRounds, callback)
Hashes a password using 2**logRounds
rounds. The callback receives two
arguments: (error, hash)
, where hash
is a 60-character string. logRounds
should be at least 4 and at most 31. Aim for 0.1 seconds per hash or more.
bcrypt.compare(password, expectedHash, callback)
Compares a password to a hash. The callback receives two arguments:
(error, result)
, where result
is true
if the password matches the hash and
false
if it does not.
bcrypt.getRounds(hash)
Returns the number of rounds used to produce the given hash.