bcryptjs
Pure JavaScript bcrypt implementation for secure password hashing without dependencies.
3. Used by agents' projects
Dependency in 196 public GitHub projects set up for AI coding agents that we scanned (3.1%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What bcryptjs does
bcryptjs is bcrypt rewritten in pure JavaScript with zero dependencies: the README says it stays compatible with the C++ binding on Node.js and also works in the browser, and says plainly that it is slower for it.
bcryptjs popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How bcryptjs is used
- bcryptjs is a dependency in 196 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (4.0% of the 4,867 JavaScript/TypeScript ones), #1 of 141 in auth and security libraries.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 505; those are left out of every share on this page.
- The most used alternative in our scan is bcrypt (JavaScript) (64 projects).
- Projects that use it most often also use Next.js (70.9%), Lucide React (68.4%), React (84.7%).
By coding agent
Often used with
bcryptjs in practice
Strengths
The README claims compatibility with the C++ <code>bcrypt</code> binding on Node.js. In the same sentence it says the library also works in the browser.
The library does not check the 72-byte input limit implicitly. The README gives the reason: "for compatibility with the C++ binding on Node.js". It leaves the check to <code>bcrypt.truncates(password)</code>.
The README says the async APIs split an operation into small chunks. Each next chunk goes to the back of the JS event queue, so other computation can run in between.
The callback versions of <code>hash</code> and <code>compare</code> accept an optional <code>ProgressCallback</code>. It reports the share of rounds completed as a number from 0.0 to 1.0.
Watch out for
The README says the library is slower than the C++ binding because it is pure JavaScript, "about 30%" by its linked benchmark. It notes this effectively reduces the number of iterations you can process in the same time.
A password longer than 72 bytes in UTF-8 is truncated when hashed. <code>bcrypt.truncates(password)</code> tells you in advance whether that will happen.
If you load the ESM build directly in a browser, you have to stub out the <code>crypto</code> import, for example with an import map. The README says bundlers should omit it automatically.
Hash and check a password (async)
import bcrypt from "bcryptjs";
const salt = await bcrypt.genSalt(10);
const hash = await bcrypt.hash("B4c0/\/", salt);
// Store hash in your password DB
// Load hash from your password DB
await bcrypt.compare("B4c0/\/", hash); // true
await bcrypt.compare("not_bacon", hash); // falseMore about bcryptjs
Funding
- GitHub Sponsors: https://github.com/dcodeIO
- 1 GitHub sponsors
Head to head
- bcryptjs vs bcrypt (JavaScript) used together in 9 projects
Packages around it
- zod: Schema validation
- next: React framework
- lucide-react: Icon set
- dotenv: Env file loader
- clsx: Class name helper
- tailwind-merge: Tailwind class merging
More in Auth and security libraries
Alternatives
bcryptjs This page
Password hashing library for secure credential storage in Node.js applications.
Get started
Install it.
npm install bcryptjsRules for your agent
## bcryptjs
- Import with `import bcrypt from "bcryptjs";`. The package exports an ES module with a UMD fallback.
- Input longer than 72 bytes in UTF-8 is truncated when hashed. The library does not check this implicitly, so call `bcrypt.truncates(password)` where necessary.
- Generated hashes are 60 characters long. Rounds default to 10 when omitted in `genSalt`, `genSaltSync` and `hashSync`.
- From a CDN, replace `TAG`/`VERSION` with a specific version. The README says omitting it to get the latest is not recommended in production.
- When using the ESM build directly in a browser, stub out the `crypto` import, for example with an import map. Bundlers should omit it automatically.
- `setRandomFallback` is only needed when neither Web Crypto nor Node.js `crypto` is available. The PRNG you pass must be cryptographically secure and seeded properly.
- `getSalt` does not validate the hash it reads from.