ShieldX Toolly
Open a tool Donate
Home Home
Blog Blog
FAQ FAQ
Open a tool Donate
Back to cheatsheets
Passwords

bcrypt Password Hashing

Generate and verify bcrypt hashes with adjustable cost factors for password storage.

2 snippets Intermediate bcrypt-generator
bcryptpassword storagecost factorhashing

What you'll learn

  • bcrypt hash (Node.js)
  • Cost factor guidance

How to use these snippets

  1. Click the Copy button next to any snippet to copy it to your clipboard.
  2. Paste the code into your project, IDE, or terminal.
  3. Replace placeholder values (like example.com or your-secret) with your actual data.
  4. Review the code comments for important security notes and caveats.
  5. Try the interactive related tool to see the concept in action.
Code Snippets

Copy-paste code snippets

2 ready-to-use snippets for bcrypt password hashing. Click copy and paste into your project.

bcrypt hash (Node.js)
                const bcrypt = require('bcryptjs');

// Hash with cost factor 12
async function hashPassword(pw) {
  const salt = await bcrypt.genSalt(12);
  return bcrypt.hash(pw, salt);
}

// Verify
async function verifyPassword(pw, hash) {
  return bcrypt.compare(pw, hash);
}
              
Cost factor guidance
                // Target: 300-500ms per hash on production hardware
// Cost 10 → ~100ms  (minimum acceptable)
// Cost 12 → ~300ms  (recommended 2025+)
// Cost 14 → ~1.2s   (high security)
// Cost 16 → ~5s     (paranoid)
//
// bcrypt limits passwords to 72 bytes.
// Pre-hash with SHA-256 if longer keys needed:
const preHash = await crypto.subtle.digest(
  'SHA-256', new TextEncoder().encode(pw)
);
              
Tool

Try this concept hands-on with the interactive tool.

100% Free · No signup · No cost

Generate something unguessable right now

148 bits of entropy, a crack-time estimate you can trust, and a clipboard that clears itself after 30 seconds.

Open the toolkit

Part of the Toolly ecosystem · secure.toolly.site