Password hashing
Module to hash values with support for PHC string format
This module is used by AdonisJs to hash the user password with first class support for upgrading logic. A big thanks to the author of uphash, who inspired me to use PHC string format. I would have used uphash directly, but the user facing API is different from what I desire.
Table of contents
Features
- Support for multiple hashing algorithms.
- Option to extend and add your own hashing algorithms.
- Wraps the hash output to a PHC string format, this allows upgrading user passwords, when the underlying configuration changes.
Usage
Install the package from npm registry as follows:
npm i @adonisjs/hash
yarn add @adonisjs/hash
and then use it as follows:
import { Hash } from '@adonisjs/hash/build/standalone'
const hash = new Hash({}, config)
const hashedValue = await hash.hash('password')
await hash.verify(hashedValue)
await hash.needsRehash(hashedValue)
Using with AdonisJs
The @adonisjs/core
module includes this module by default. However, here's how you can set it up manually.
const providers = [
'@adonisjs/hash'
]
And then also register the typings file inside tsconfig.json
file.
{
"files": ["./node_modules/@adonisjs/hash/build/adonis-typings/hash.d.ts"]
}
And use it as follows:
import Hash from '@ioc:Adonis/Core/Hash'
await Hash.hash('password')
Switching drivers
You can switch drivers using the use
method.
await Hash.use('bcrypt').hash('password')
Audit report
Click here to see the latest npm audit report.