← All packages

@lacspace/password

v1.0.5Security Kit1 @lacspace dep

Password hashing & verification — PBKDF2-HMAC-SHA256 (OWASP iterations) with a portable PHC string + a strength estimator. Isomorphic over Web Crypto.

npm i @lacspace/password

Usage

password.ts
import { hash, verify, needsRehash, strength } from "@lacspace/password";

const stored = await hash("correct horse battery staple");
// "$pbkdf2-sha256$i=600000$<salt>$<hash>"  — store this string

await verify("correct horse battery staple", stored); // true
await verify("wrong", stored);                          // false

if (needsRehash(stored)) { /* re-hash with current params after a successful login */ }

strength("password");        // { score: 0, warnings: ["This is a very common password."] }
strength("Tr0ub4dour&3xy");  // { score: 4, warnings: [] }

Exports 4

hashneedsRehashstrengthverify

Keywords

passwordhashpbkdf2password-hashingverifyphc

More in Security Kit