password-hash-ts
v1.0.1
Published
Zero-dependency TypeScript library for PBKDF2 password hashing across Node, browser and React environments.
Maintainers
Readme
password-hash-ts
Current version: v1.0.1
Password-hash-ts is a zero-dependency TypeScript library for secure PBKDF2 password hashing across Node.js, React, and browser environments. It uses platform-native cryptography (Web Crypto / Node.js crypto), produces self-contained hashes, and ships ESM, CJS and browser bundles.
Short description: Secure, portable PBKDF2 password hashing for Node, React, and browser apps.
Examples
Node.js (ESM)
import { hashPassword, verifyPassword, isHash, needsRehash, estimateStrength } from "password-hash-ts";
const password = "MyStrongPassword123!";
const hash = await hashPassword(password);
console.log("Hash:", hash);
console.log("Verify:", await verifyPassword(password, hash));Node.js (CommonJS)
const { hashPassword, verifyPassword } = require("password-hash-ts");
(async () => {
const hash = await hashPassword("secret123");
console.log("Hash:", hash);
console.log("Verify:", await verifyPassword("secret123", hash));
})();React (hooks)
import React, { useEffect, useState } from "react";
import { hashPassword, verifyPassword } from "password-hash-ts";
function Example() {
const [hash, setHash] = useState(null);
useEffect(() => {
(async () => {
const h = await hashPassword("MyReactPassword!");
setHash(h);
const ok = await verifyPassword("MyReactPassword!", h);
console.log("Verified in React:", ok);
})();
}, []);
return <div>Hash: {hash}</div>;
}
export default Example;Features
- PBKDF2 with SHA-256 (default)
- Cross-platform: Web Crypto and Node.js crypto
- Self-contained hash format: pbkdf2$sha256$iterations$salt$hash
- Zero runtime dependencies
