password-better-hash

1.0.2 • Public • Published

password-better-hash

CircleCI XO code style code style: prettier install size Downloads

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.

Install

$ npm install --save password-better-hash

Usage

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
 

API

passwordBetterHash(password, options?)

Returns a hash.

password

Type: string

Password you want to hash.

options

Type: object

saltSize

Type: integer

Default: 64

Salt size in bytes.

iterations

Type: integer

Default: 10000

Number of iterations for pbkdf2.

encoding

Type: string

Default: base64

Values: All available encodings that Node.js supports

algorithm

Type: string

Default: sha512

Values: Platform dependent, please use crypto.getHashes() to get the available algorithms.

passwordBetterHash.async(password, options?)

Returns a hash asynchronously.

passwordBetterHash.compare(password, hash, options?)

Returns a boolean.

hash

Type: string

Hash you want to compare.

passwordBetterHash.compareAsync(password, hash, options?)

Returns a boolean asynchronously.

License

MIT

Package Sidebar

Install

npm i password-better-hash

Weekly Downloads

8

Version

1.0.2

License

MIT

Unpacked Size

11.4 kB

Total Files

10

Last publish

Collaborators

  • acestojanoski