1.0.4 • Published 4 years ago

@amirabbas/hash-util v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

hash-util

hashing util based on nodejs built-in module 'crypto'

Installation

you can install this module whether via npm:

npm i @amirabbas/hash-util

or yarn:

yarn add @amirabbas/hash-util

Documentation

.hash

returns a string containing the hash and the salt

  • password {crypto.BinaryLike}: the password, secret or anything (BinaryLike which string are included in it) to hash
  • keylen {number}: optional hash length (default is 64)
  • salt{crypto.BinaryLike}: optional salt used when hashing (it's safer not to pass it)

    .compare

    returns a boolean which is true if the passed hash and the password match

  • hashString {string}: hashString to compare (which should contain the salt separated with a dot ("{salt}.{hash}"))

  • password {crypto.BinaryLike}: password to be check if it matches the given hash
  • keylen{number}: optional hash length (default is 64)

Usage

basic usage

import {hash, compare} from '@amirabbas/hash-util'; //there is also a default exportation to avoid name conflicts

const secret = "mySuperSecurePassword"; //your password to hash

(async ()=>{
  const hashedPwd = await hash(secret)
  console.log(hashedPwd) //"{salt}.{hash}"
  
  const samePwd = await compare(hashedPwd, secret) 
  console.log(samePwd) //true
})()
1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago