@rudderjs/hash
v1.0.0
Published
One-way password hashing for RudderJS. Built-in drivers: **bcrypt** (default) and **argon2**.
Downloads
1,326
Readme
@rudderjs/hash
One-way password hashing for RudderJS. Built-in drivers: bcrypt (default) and argon2.
Installation
pnpm add @rudderjs/hashFor argon2 support:
pnpm add argon2Setup
// config/hash.ts
export default {
driver: 'bcrypt',
bcrypt: { rounds: 12 },
argon2: { memory: 65536, time: 3, threads: 4 },
}
// bootstrap/providers.ts
import { hash } from '@rudderjs/hash'
export default [hash(configs.hash), ...]Usage
import { Hash } from '@rudderjs/hash'
// Hash a password
const hashed = await Hash.make('password')
// Verify a password
const valid = await Hash.check('password', hashed) // true
// Check if rehash is needed (e.g. after changing rounds)
if (Hash.needsRehash(hashed)) {
const newHash = await Hash.make('password')
}Drivers
Bcrypt (default)
Uses bcryptjs (pure JS, no native compilation needed).
| Option | Default | Description |
|--------|---------|-------------|
| rounds | 12 | Cost factor (2^rounds iterations) |
Argon2
Uses the argon2 package (native, requires compilation). Uses argon2id variant.
| Option | Default | Description |
|--------|---------|-------------|
| memory | 65536 | Memory cost in KiB |
| time | 3 | Time cost (iterations) |
| threads | 4 | Parallelism factor |
