Bcrypt hashes Node.js will accept
Set to the $2b$ prefix and cost 12 that Node.js expects. Change either one if your project has been configured differently. Nothing you type here leaves the browser.
Everything here runs locally
PHP counts only $2y$ as bcrypt, so Laravel Hash::check() rejects this hash with "This password does not use the Bcrypt algorithm" before it compares anything. Pick $2y$ for PHP, Laravel or Symfony. Why the prefix matters
Both the native bcrypt package and the pure JavaScript bcryptjs write the $2b$ prefix. Use the async calls in a server, since the sync ones block the event loop for the entire cost of the hash.
The same thing in Node.js
Hashing in Node.js
import bcrypt from 'bcryptjs';
const hash = await bcrypt.hash('correct horse battery staple', 12);Checking a password
const ok = await bcrypt.compare(req.body.password, user.passwordHash);From a terminal
node -e "import('bcryptjs').then(b => b.hash('correct horse battery staple', 12).then(console.log))"Check a hash from your database
Paste a stored hash and a candidate password to confirm they match, which is a quick way to rule the hash out when a login is failing for reasons you cannot see.
Verification also runs locally
Other stacks
- Laravel Bcrypt hashes with the $2y$ prefix and Laravel defaults.
- PHP Hashes that PHP password_verify accepts, with the $2y$ prefix.
- Python Hashes for the Python bcrypt package and passlib, $2b$ prefix.
- Java Hashes for jBCrypt and Spring Security, $2a$ prefix.
- Spring Security Hashes for BCryptPasswordEncoder, $2a$ prefix at strength 10.
- Go Hashes for golang.org/x/crypto/bcrypt, $2a$ prefix.