bcryptjs
Pure JavaScript bcrypt password hashing — no native dependencies, same API as bcrypt, works anywhere Node.js runs.
bcryptjs
Node.jsPure JavaScript bcrypt password hashing — no native dependencies, same API as bcrypt, works anywhere Node.js runs.
Fit
Bundle (gzip)
9.2 kB
20.1 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
Storing passwords in plain text or with weak hashes (MD5, SHA-1) is a critical security vulnerability. bcrypt's built-in salt and cost factor make brute-force attacks computationally expensive.
What It Does
bcryptjs hashes passwords with bcrypt's adaptive algorithm — the cost factor controls how slow the hash is, making it future-proof as hardware improves. compare safely verifies passwords against stored hashes without timing attack vulnerabilities. No native modules means it works in serverless environments.
Installation
npm install bcryptjs
npm install -D @types/bcryptjsUsage Example
import bcrypt from 'bcryptjs';
// Hash a password before storing
async function hashPassword(password: string): Promise<string> {
const saltRounds = 12;
return bcrypt.hash(password, saltRounds);
}
// Verify a password at login
async function verifyPassword(password: string, hash: string): Promise<boolean> {
return bcrypt.compare(password, hash);
}
// Usage
const hash = await hashPassword('mySecurePassword');
const isValid = await verifyPassword('mySecurePassword', hash); // trueRelated packages
Role and attribute based access control (RBAC + ABAC) for Node.js with a fluent, readable API.
bullmqNode.jsPremium message queue and job scheduler for Node.js backed by Redis — reliable background job processing with retries, priorities, and rate limiting.
casbinNode.jsA powerful authorization library that supports RBAC, ABAC, ACL and more via configurable policy models.
dotenvNode.jsLoad environment variables from a `.env` file into `process.env` — the standard way to manage configuration in Node.js apps.
execaNode.jsProcess execution for Node.js — a better child_process with Promises, streaming, and a clean cross-platform API.