Skip to content
Agents tracked: 440 Downloads (7d): 202M down 19.5% GitHub stars: 10.4M Releases (7d): 607 Agent status: 3 with issuesSince last limit reset: Claude 28d · Codex 0d Updated Oct 21, 2026

Synchronous hashing in bcryptjs

The sync API returns results directly instead of a promise, which keeps scripts and small tools short. The same hash format works with the async API.

All bcryptjs examples bcryptjs: usage and stats

Synchronous hashing in bcryptjs: screenshot of the example below running
The code below, running in Chromium on our server (Oct 12, 2026). Press Run to see it live and change it.

How it works

  1. Salt, then hash. bcrypt.genSaltSync(10) returns a salt string, and bcrypt.hashSync(password, salt) returns the hash right away. [1]
  2. Auto-generate the salt. Passing a number instead of a salt, as in bcrypt.hashSync(password, 10), creates the salt for you. Hashing the same password twice gives two different hashes because each gets its own salt. [1]
  3. Verify with compareSync. bcrypt.compareSync(password, hash) returns a boolean. Both hashes validate the same password. [1]

Run and edit it

It runs in your browser, in a sandboxed frame that cannot see this site; the packages load from esm.sh only after you press Run.

import bcrypt from 'bcryptjs'

const password = 'hunter2'

// Explicit salt
const salt = bcrypt.genSaltSync(10)
const hashA = bcrypt.hashSync(password, salt)

// Salt generated from a round count
const hashB = bcrypt.hashSync(password, 10)

console.log('Salt:   ', salt)
console.log('Hash A: ', hashA)
console.log('Hash B: ', hashB)
console.log('Same hash twice?', hashA === hashB)

console.log('compareSync(password, hashA):', bcrypt.compareSync(password, hashA))
console.log('compareSync(password, hashB):', bcrypt.compareSync(password, hashB))
console.log('compareSync("hunter3", hashA):', bcrypt.compareSync('hunter3', hashA))
Ctrl/⌘ + Enter runs

Free for signed-in members, with a daily limit. Describe the change in plain words; the new code runs only in your browser.

Run it twice: the two hashes differ every time, but both compareSync checks print true. Code written by AgentGid [1].

Checked Oct 12, 2026: it starts without errors in Chromium with bcryptjs 3.0.3. Needs WebGL.

More bcryptjs examples

Hashing and checking a password with bcryptjs Salt rounds and cost in bcryptjs Checking the 72-byte limit with bcryptjs Hash progress and callbacks in bcryptjs

Sources

  1. bcryptjs README (GitHub)

Explanations written by AgentGid from the official docs; the numbers in brackets point here. The code marked "written by AgentGid" is ours and free to copy.

Building something with bcryptjs? Ask AgentGid →