1.0.4 • Published 5 years ago
@amirabbas/hash-util v1.0.4
hash-util
hashing util based on nodejs built-in module 'crypto'
Installation
you can install this module whether via npm:
npm i @amirabbas/hash-utilor yarn:
yarn add @amirabbas/hash-utilDocumentation
.hash
returns a string containing the hash and the salt
password{crypto.BinaryLike}: the password, secret or anything (BinaryLikewhichstringare included in it) to hashkeylen{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 hashkeylen{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
})()