user-auth

3.0.2 • Public • Published

Build Status

Synopsis

Hashes and verifies passwords

Usage

Promise based library used to create valid passwords for users which can be safely stored in the database as a hash and corresponding salt. Valid passwords are defined as:

  • At least six characters
  • Match at least three of the following criteria
    • One uppercase letter
    • One lowercase letter
    • One number
    • One symbol

Examples of valid passwords:

haPpy3
t1gg@r
H3R3$ME

Uses Crypto.pbkdf2 using SHA-1 hash and a 128-byte salt to generate a 512-byte key.

Installation

Install npm packages

npm install --save user-auth

Example

var userAuth = require('user-auth');
 
userAuth.generate('haPpy3')
.then(function (user) {
  console.log('hash', user.hash, 'salt', user.salt); // long random strings
  return userAuth.authenticate('haPpy3', user)
})
.then(function (isValid) {
  console.log('Verified?', isValid); // true!
})

or

const userAuth = require('user-auth');
 
async function example() {
  const {hash, salt} = await userAuth.generate('haPpy3');
  console.log('hash', hash, 'salt', salt); // long random strings
  const isAuthenticated = await userAuth.authenticate('haPpy3', {hash, salt});
  console.log('Verified?', isAuthenticated);// true!
}

Package Sidebar

Install

npm i user-auth

Weekly Downloads

1

Version

3.0.2

License

MIT

Unpacked Size

16.4 kB

Total Files

9

Last publish

Collaborators

  • jkmart