@kdcsoftware/password

0.3.0 • Public • Published

Password Hash and Salt Generator

ver build codecov size license

Maintainability Code Issues Technical Debt

This package will generate hash and salt given a password. It also has a function to validate a password input.

Install

npm i @kdcsoftware/password

Usage

On user registration

const { getHashSalt } = require('@kdcsoftware/password');

const register = (password) => {
    ...
    const {hash, salt} = getHashSalt(password);
    ...
};

Store the hash and salt in your database.

On user login

const { isValidPassword } = require('@kdcsoftware/password');

const login = (username, password) => {
    ...
    const {hash, salt} = getFromDatabase(username);
    if(isValidPassword(password, hash, salt)) {
        console.log("Password is correct");
    } else {
        console.log("Password is wrong");
    }
    ...
};

Configuration

Iterations, keylen and digest can be configured by defining environment variables.

  • PW_ITERATIONS
  • PW_KEYLEN
  • PW_DIGEST

See algorithms in NodeJs crypto docs for possible values for digest. More info on the link below.

Reference

https://nodejs.org/api/crypto.html#crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback

Readme

Keywords

Package Sidebar

Install

npm i @kdcsoftware/password

Weekly Downloads

0

Version

0.3.0

License

MIT

Unpacked Size

15.6 kB

Total Files

16

Last publish

Collaborators

  • ianpogi5
  • mbungalso