A simple package to work with password in JS / TS
npm
npm install wops
yarn
yarn add wops
import {
generatePassword,
validatePassword,
hashPassword,
checkPasswordStrength
} from 'wops'
const password = generatePassword(10, true)
const { hash, salt } = hashPassword("YOUR PASSWORD")
const isValid = validatePassword("YOUR PASSWORD", salt, hash)
const passwordStrength = checkPasswordStrength("YOUR PASSWORD")
- generatePassword(length, useUpper, useNumber, useSpecial) ⇒
string
Generates a password according to the specified parameters
- hashPassword(pswd) ⇒
HashAndSalt
Given a Password, hash it with a salt, then return the hash and the salt
- validatePassword(inpPswd, salt, storedHash) ⇒
boolean
Given an input password a salt and an hash Does the given password match with the hash?
- checkPasswordStrength(pswd)
The checkPasswordStrength function checks how strong the entered password is
- HashAndSalt :
Object
Generates a password according to the specified parameters
Kind: global function
Returns: string
- password
Param | Type |
---|---|
length | string |
useUpper | boolean |
useNumber | boolean |
useSpecial | boolean |
hashPassword(pswd) ⇒ HashAndSalt
Given a Password, hash it with a salt, then return the hash and the salt
Kind: global function
Returns: HashAndSalt
- object containing the hash and the salt used
Param | Type |
---|---|
pswd | string |
Does the given password match with the hash?
Kind: global function
Returns: boolean
- does hash(inpPswd + salt) === storedHash?
Param | Type |
---|---|
inpPswd | string |
salt | string |
storedHash | string |
The checkPasswordStrength function checks how strong the entered password is
Kind: global function
Param | Type |
---|---|
pswd | string |
Kind: global typedef Properties
Name | Type | Description |
---|---|---|
hash | string |
The hash we got |
salt | string |
The salt used for hashing |