Easy and secure password hashing with salt.
- 100% tested.
- No dependencies.
- Uses a strong hash algorithm by default (sha256).
- Appends a random string (salt) to each password before hashing it (for extra security).
- JSDoc documentation for completion in editors like VS Code.
npm i pw-hash
const hash = require('pw-hash')
// hash a password:
const hashString = hash.create('example password')
// verify if a password matches
hash.verify('wrong password', hashString) // false
hash.verify('example password', hashString) // true
- password
<string>
- A string containing the password.
Returns a string that can be stored in the database. It can be used with the verify method to check if a password matches.
- password
<string>
- A string containing the password. - hashString
<string>
- A string that was created with the .create() method.
This method verifies if the password is the same password that you passed to the .create() method.
It Returns true
if the password matches or false
if it doesn't.