A better password hashing utility with zero dependencies
Utility for hashing passwords, and comparison between the password and the hash. It is using pbkdf2
and pbkdf2Sync
functions from the Node.js crypto
module.
$ npm install --save password-better-hash
const hash = require('password-better-hash');
console.log(hash('strong-password'));
// output: ok8VoFbft4q83tqfjvUjebCHDK7/PWbUVI+h6ip2NAOVUZBR0JUquQkChJum7 ...
const hash = require('password-better-hash');
hash.async('strong-password').then(console.log);
// output: fhge26w/RmgMUL1OI28/I30ktnLzj9Nl2mWdieOFuuo1hbG0cMqzM8omfQYpv4T2 ...
const hash = require('password-better-hash');
console.log(hash.compare('strong-password', 'fhge26w/RmgMUL1OI28/I30ktnLzj9Nl2mWdieO...'));
// output: true
const hash = require('password-better-hash');
hash.compareAsync('strong-password', 'invalid hash')
.then(console.log);
// output: false
Returns a hash.
Type: string
Password you want to hash.
Type: object
Type: integer
Default: 64
Salt size in bytes.
Type: integer
Default: 10000
Number of iterations for pbkdf2.
Type: string
Default: base64
Values: All available encodings that Node.js supports
Type: string
Default: sha512
Values: Platform dependent, please use crypto.getHashes()
to get the available algorithms.
Returns a hash asynchronously.
Returns a boolean
.
Type: string
Hash you want to compare.
Returns a boolean
asynchronously.