Licence
Unlicense
Version
1.0.0
Deps
1
Size
6 kB
Vulns
1
Weekly
0
bcrypt-password-hash
hash password with bcrypt
Generation and validation of passwords using bcrypt hashes. Uses same api as pbkdf2-password-hash.
Requires node >= v8.0.0
TOC
Example
Generate new password hash
const passwordHash = require('bcrypt-password-hash')
// generates random salt
passwordHash.hash('password')
.then((hash) => {
//> hash === 'bcrypt$2b$10$Y6MKD5ZI5gtkvBdYyqwr1.CrHA66ppM/9YNDvacUuqWZSVduKQcIq'
})
Generate password hash with different options
passwordHash.hash('password', {saltRounds: 14})
.then((hash) => {
//> hash === 'bcrypt$2b$14$9zjobUQJ9LVswQrQJ7leKe6NnJKMc3ZouykkhZZ6uFa9ARMZVSUgy'
})
Validate password hash
const hash = 'bcrypt$2b$14$9zjobUQJ9LVswQrQJ7leKe6NnJKMc3ZouykkhZZ6uFa9ARMZVSUgy'
passwordHash.compare('password', hash)
.then((isValid) => {
//> isValid === true
})
API
hash(password, [salt], [opts])
Generate a new password hash for password using bcrypt.
Parameters
| parameter | type | description |
|---|---|---|
password |
String | |
[salt] |
String | optional: salt |
[opts.saltRound=10] |
Number | optional: number of iterations |
Returns Promise, hashed password in bcrypt__INLINE_CODE_7__lt;version>__INLINE_CODE_7__lt;saltRound>__INLINE_CODE_7__lt;salt><hash> notation.
compare(password, passwordHash)
validate password against passwordHash
Parameters
| parameter | type | description |
|---|---|---|
password |
String | plain-text password |
passwordHash |
String | hashed password |
Returns Promise, true if hash matches password
Installation
Requires nodejs >= v8.0.0
$ npm install --save bcrypt-password-hash
Tests
$ npm test
LICENSE
UNLICENSE https://unlicense.org