Use this when storing passwords with bcrypt.
bcrypt
bcrypt is a well-established password hashing algorithm with a salt and adjustable cost factor, such as cost 12. It truncates passwords at 72 bytes, which matters for very long passphrases.
1. bcrypt: adaptive cost, widely supported.
2. 72-byte password limit.
3. Cost 10–12+.
4. Not memory-hard but still acceptable.
5. Upgrade cost over time.
password + salt + cost → bcrypt hash
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Common mistakes Narrow the fault
- bcrypt input truncated at 72 bytes.
- Cost factor never increased.
Step 2 bcrypt limits Narrow the fault
- Only the first 72 bytes of the password are used; long passphrases are silently truncated.
- Pre-hashing to avoid the limit must be encoded (base64) to avoid null bytes.
- Not memory-hard; prefer Argon2id for new systems.
- Cost factor should be raised over time (each +1 doubles the work).
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- The cost factor sets work per hash.
- Passwords are truncated at 72 bytes.
- The salt is included in the hash string.
python3 -c "import bcrypt;print(bcrypt.hashpw(b'pw',bcrypt.gensalt(12)))"— bcrypt cost 12- Cost factor — ≥ 10–12
- 72-byte input limit — pre-hash handling
ReferenceWhy it matters1 section · depth on demand
Using bcrypt
- Cost factor is logarithmic: each +1 doubles the work. Choose about 100 ms per hash on your servers (often cost 12).
- Only the first 72 bytes of the password are used; long passphrases are truncated. Some libraries pre-hash to avoid this.
- The hash string stores algorithm, cost and salt:
$2b$12$<22-char salt><31-char hash>.
bcrypt is not memory-hard, so Argon2id is preferred for new systems.
ReferenceImportant terms & boundaries2 sections · depth on demand
In depth
bcrypt is a password hashing function based on the Blowfish cipher, with a configurable cost factor that doubles the work for each increment. It has been widely used since 1999 and is supported in almost every language and framework.
import bcrypt
h = bcrypt.hashpw(password.encode(), bcrypt.gensalt(rounds=12))
bcrypt.checkpw(password.encode(), h)
$2b$12$<22-char salt><31-char hash>
Documented example, not captured output.
Notes: use cost 12 or higher (tune so hashing takes ~100–300 ms), be aware that input beyond 72 bytes is ignored (pre-hash long inputs carefully or prefer Argon2id), and bcrypt is not memory-hard, so Argon2id is preferred for new systems.
Hash format
$2b$12$R9h/cIPz0gi.URNNX3kh2OPST9/PgBkqquzi.Ss7KIUgO2t0jWMUW
| | | |
| | salt (22 chars) hash (31 chars)
| cost (2^12 rounds)
version
Documented example, not captured output. PHP password_hash($p, PASSWORD_BCRYPT, ['cost' => 12]) and password_verify() handle this format.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Hashing → bcrypt. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://csrc.nist.gov/pubs/fips/180-4/upd1/final · confidence 94%