bcrypt is a password hashing function designed to be computationally expensive, making brute-force attacks impractical. It incorporates a salt and configurable work factor, automatically adapting to increased computing power over time.
bcrypt uses the Blowfish cipher in a key setup phase that is deliberately slow. The work factor (cost) determines how many iterations are performed, with each increment doubling the computation time.
$2b$12$R9h/cIPz0gi.URNNX3kh2OPST9/PgBkqquzi.Ss7KIUgO2t0jWMUW
│ │ │ │
│ │ │ └── Hash (31 characters)
│ │ └── Salt (22 characters, base64)
│ └── Cost factor (2^12 = 4096 iterations)
└── Algorithm version ($2a$, $2b$, $2y$)
# Python
import bcrypt
# Hash a password
password = b"secretpassword"
salt = bcrypt.gensalt(rounds=12) # Cost factor
hashed = bcrypt.hashpw(password, salt)
# Verify password
if bcrypt.checkpw(password, hashed):
print("Password matches")
Note: bcrypt is NOT memory-hard like scrypt or Argon2. Its GPU resistance comes from Blowfish's 4KB S-box requiring frequent random memory accesses (latency-bound), not from consuming large amounts of memory. For maximum resistance to modern hardware attacks, consider Argon2id.