.env · security🔒 100% client-side — never leaves your browser

Bcrypt Generator: hash and verify passwords

Generate a bcrypt hash or check a password against one: this bcrypt generator hashes in your browser with bcryptjs, lets you choose the cost factor, and produces standard $2b$ hashes that PHP, Node.js, Python, Ruby and Go all accept.

By Aliniyaz Mamat · last reviewed

Be the first to rate
Password / plaintext
Cost factor (rounds) — higher = slower = more secure
Rounds 10–12 are standard. Each +1 doubles hashing time.
CLI equivalents
Node.js (bcryptjs)
node -e "const b=require('bcryptjs'); console.log(b.hashSync('pw',12))"
Python (bcrypt)
python3 -c "import bcrypt; print(bcrypt.hashpw(b'pw',bcrypt.gensalt(12)))"

Key takeaways

  • ✓Each +1 on the cost factor doubles the work: cost 12 is 4× slower than cost 10. OWASP's minimum for bcrypt is 10.
  • ✓Format: $2b$12$ + 22-character salt + 31-character hash = 60 characters. The salt is random, so the same password gives a new hash every time.
  • ✓bcrypt only reads the first 72 bytes (UTF-8). The counter under the input warns you when a password is longer.
  • ✓For new systems OWASP recommends Argon2id first; bcrypt remains a solid choice where Argon2 isn't available.
  • ✓Passwords and hashes are processed locally; nothing is uploaded.

What it does

  • ▸Hash passwords with cost factor 10 to 14
  • ▸Verify a password against an existing bcrypt hash
  • ▸Standard $2b$ output, compatible with all major libraries
  • ▸72-byte length warning
  • ▸Runs in your browser with bcryptjs

Privacy

Runs 100% in your browser. Your .env never touches our servers.

client-side only

When to use this tool

  • →Seeding an admin user's password hash into a database or a migration
  • →Setting ADMIN_PASSWORD_HASH in a .env instead of a plain-text password
  • →Creating htpasswd-style entries for tools that accept bcrypt (Traefik, Caddy, Nginx with bcrypt support)
  • →Checking whether a stored hash really matches a password while debugging a login

Common mistakes

  • ⚠Hashing API keys or tokens with bcrypt: they are random already, a fast SHA-256 is enough (see the API key generator)
  • ⚠Choosing cost 14 on a busy login endpoint: each login then takes about a second of CPU
  • ⚠Pre-hashing with SHA-256 and passing raw bytes: a null byte can cut the input. Hex- or base64-encode the digest first
  • ⚠Comparing hashes with ===. Always use the library's compare function, which re-hashes with the stored salt

Choosing the cost factor

CostIterations (2^cost)Relative timeUse for
101,0241×minimum (OWASP), very high login volume
112,0482×high-traffic apps
124,0964×common default in Laravel and many frameworks
138,1928×admin accounts, low-volume apps
1416,38416×offline secrets, rarely-used logins

Measure on your production hardware: pick the highest cost where one hash still takes well under a second (100–300 ms is typical). Raise it over the years; most libraries re-hash on login when the stored cost is lower than the configured one.

Hashing and verifying in your language

// Node.js: npm i bcrypt (native) or bcryptjs (pure JS)
import bcrypt from "bcrypt";
const hash = await bcrypt.hash(password, 12);
const ok = await bcrypt.compare(password, hash);
import bcrypt
hashed = bcrypt.hashpw(password.encode(), bcrypt.gensalt(rounds=12))
ok = bcrypt.checkpw(password.encode(), hashed)
$hash = password_hash($password, PASSWORD_BCRYPT, ['cost' => 12]);
$ok = password_verify($password, $hash);

$2a$, $2b$ and $2y$ (PHP) prefixes are interchangeable for verification in current libraries. When you put a hash into a .env file, wrap it in single quotes: the $ signs would otherwise be read as variable references by dotenv-expand and Docker Compose.

bcrypt vs Argon2id vs scrypt vs SHA-256

AlgorithmBuilt for passwordsMemory-hardNotes
Argon2idyesyesOWASP's first choice for new systems
scryptyesyesgood alternative, used by Node's built-in crypto.scrypt
bcryptyesnobattle-tested since 1999, 72-byte input limit
PBKDF2yesnoFIPS-approved; needs very high iteration counts
SHA-256 / MD5nonobillions of guesses per second on a GPU; never for passwords

The difference that matters for stolen databases is speed: a fast hash lets an attacker test huge password lists cheaply, a deliberately slow one does not. Keep the rest of your secrets out of reach too, see .env best practices.

Frequently asked questions

What is the difference between bcrypt and SHA-256?

SHA-256 is designed to be fast, so a GPU can try billions of passwords per second against it. bcrypt is deliberately slow and salted, which makes brute-forcing a leaked hash impractical.

What cost factor should I use?

At least 10 (OWASP's minimum). 12 is a common default today. Choose the highest value your login endpoint can afford, measured on your own servers.

Can bcrypt handle passwords longer than 72 bytes?

No, it ignores everything after the 72nd byte. Either limit password length, or pre-hash with SHA-256 and encode the result as hex or base64 before bcrypt, as Django's BCryptSHA256PasswordHasher does.

Why does the same password give a different hash each time?

bcrypt adds a new random 16-byte salt to every hash and stores it inside the hash string. Verification reads that salt back, so different hashes of the same password all verify.

Is my password sent to a server?

No. Hashing and verification run in your browser with the bcryptjs library.

Related tools

Learn more

Compare

coming soon

Get notified when env syncing launches

We're building a tiny tool to keep .env files in sync across teammates and environments. Leave your email — no spam, just a single launch ping.

We use your address only for this launch email. You can ask us to delete it at any time. Privacy policy