Password Security Guide: Entropy, Hashing & Best Practices for Developers

In 2024, "123456" was still the most common password worldwide. But even a strong password is only as secure as how it's stored. This guide covers password security from both sides — generating strong passwords and storing them safely as a developer.

Password Entropy: Measuring Strength

Entropy quantifies how unpredictable a password is, measured in bits:

Entropy = log₂(character_pool ^ length)

Character SetPool Size8 chars12 chars16 chars
Lowercase only2637 bits56 bits75 bits
Lower + Upper5246 bits68 bits91 bits
Lower + Upper + Digits6248 bits71 bits95 bits
All printable ASCII9452 bits78 bits105 bits
💡 Key insight: Length beats complexity. A 16-character lowercase password (75 bits) is stronger than an 8-character password with every character type (52 bits). Always prioritize length.

How Passwords Should Be Stored

Never store passwords in plain text or with reversible encryption. The correct approach is one-way hashing with a salt:

  1. Generate a unique random salt (16-32 bytes) for each password
  2. Hash: stored_hash = hash_function(salt + password)
  3. Store the salt and hash together (most algorithms handle this automatically)
  4. To verify: recompute the hash with the same salt and compare

Password Hashing Algorithms Compared

AlgorithmCPU-HardMemory-HardParallelism ResistanceRecommendation
Argon2idBest choice for new applications
bcryptModerateExcellent, widely supported
scryptGood alternative to Argon2
PBKDF2NIST-approved, but vulnerable to GPU attacks
SHA-256Never use for passwords
MD5Broken — never use

Why General-Purpose Hashes Fail for Passwords

SHA-256 can compute billions of hashes per second on a modern GPU. An 8-character password using all printable ASCII (52 bits of entropy) can be brute-forced in under 24 hours. Password-specific algorithms add a configurable work factor that makes each hash computation intentionally expensive:

  • bcrypt with cost factor 12: ~250 ms per hash → brute-forcing 52-bit password takes centuries
  • Argon2id with 64 MB memory, 3 iterations: ~500 ms per hash, plus requires 64 MB RAM per attempt

Salting: Why Every Password Needs Its Own

Without salts, identical passwords produce identical hashes. An attacker with a stolen database can:

  • Use precomputed rainbow tables to instantly reverse common password hashes
  • Identify users sharing the same password (they'll have the same hash)
  • Crack one password and compromise all accounts using it

A unique salt per password defeats all of these attacks. Both bcrypt and Argon2 handle salting automatically — the salt is embedded in the output string.

Password Generation Best Practices

  • Use a cryptographically secure random number generatorcrypto.getRandomValues() in browsers, secrets module in Python, SecureRandom in Java
  • Never use Math.random() for security purposes — it's not cryptographically secure
  • Minimum 12 characters for standard accounts, 16+ for high-security
  • Passphrases work — 4-5 random dictionary words provide both high entropy and memorability
  • Avoid patterns — "Password1!" meets most complexity requirements but is trivially crackable

Common Password Security Mistakes

  • Storing passwords in plain text — any database breach exposes all credentials
  • Using MD5 or SHA-1 — both are computationally broken for password use
  • Enforcing maximum length limits — if you're hashing, the input length doesn't affect storage
  • Requiring frequent password changes — NIST no longer recommends this; it leads to weaker passwords
  • Blocking paste in password fields — this discourages password manager use
  • Rolling your own crypto — use established libraries (bcryptjs, argon2, passlib)

Frequently Asked Questions

SHA-256 is designed to be fast — attackers can compute billions of hashes per second. Password-specific algorithms like bcrypt and Argon2 are intentionally slow, making brute-force attacks computationally infeasible.
Entropy measures unpredictability in bits: entropy = log₂(characters^length). A 12-character password with all printable ASCII has ~78 bits of entropy. 80+ bits is considered very strong.
Both are password hashing algorithms. Argon2 is more modern and adds memory-hardness, making it resistant to GPU and ASIC attacks. Argon2id is recommended for new applications; bcrypt remains secure and widely supported.
A salt is a random value unique to each password that ensures identical passwords produce different hashes, defeating rainbow table attacks. bcrypt and Argon2 handle salting automatically.
Minimum 12 characters for important accounts, 16+ for high-security. Length matters more than complexity — a 16-character lowercase password is stronger than an 8-character one with symbols.

Generate a strong password

Open Password Generator →