Password Security
Identity & Access

Password Security

A complete guide to Password Security: password entropy, slow hashing algorithms (Argon2id, bcrypt), salts, rainbow tables, and credential defense.

Every day, attackers use high-speed computer hardware to test billions of password guesses per second against leaked database files. Specialized graphics cards (GPUs) can calculate standard cryptographic hashes at incredible speeds. If an account is protected with a common password or a predictable pattern (like adding '!' or '123' to a dictionary word), automated cracking tools will discover it in seconds. Worse, if developers store passwords improperly in a database, a single leak can compromise accounts across multiple websites. Password security is the practice of creating strong passphrases and using modern, memory-hard hashing algorithms so that stored credentials remain protected even if a database file is compromised.

Definition

Password Security is the set of practices and cryptographic methods used to create, store, and verify passwords securely, protecting them against guessing, dictionary attacks, and automated brute-force cracking.

Why It Matters

Improper password storage has led to some of the largest data breaches in internet history. In past breaches at major companies, passwords were saved in plain text or with outdated hashing algorithms, allowing attackers to unlock millions of user passwords within hours. Understanding modern password security ensures developers protect user credentials using proper slow hashing, and helps individuals adopt password habits that keep their accounts safe.

How It Works

Four core principles define modern password security: 1. Password Length vs Complexity (Entropy): Entropy measures how unpredictable a password is. Length adds far more security than arbitrary character rules: • A short, complex password like `aB3!zX9#` is difficult for humans to remember, but easy for modern computers to crack through brute force. • A long passphrase made of four random common words (such as `correct-horse-battery-staple`) is easy for humans to remember, but takes computers millions of years to guess because of the vast number of possible word combinations. 2. Never Store Plaintext Passwords: Servers should never store actual passwords or reversible encryption. Instead, the server runs the password through a one-way cryptographic hash function and stores only the resulting hash digest. When the user logs in later, the server hashes the entered password and checks if the two hashes match. 3. Fast Hashes vs Slow Hashes: • Fast Hashes (MD5, SHA-1, SHA-256): These algorithms were designed to check file integrity quickly. They are dangerous for passwords because computers and GPUs can calculate billions of guesses every second. • Slow, Memory-Hard Hashes (Argon2id, bcrypt, scrypt): These algorithms were created specifically for passwords. They deliberately use computer memory and processor time to calculate each hash. Argon2id, the current standard, requires tens of megabytes of RAM per calculation, making it virtually impossible for attackers to run massive parallel cracking rigs. 4. Cryptographic Salts: A Rainbow Table is a precomputed dictionary of common passwords and their corresponding hash values. If two users have the same password, their hashes would be identical. A Salt is a unique, random string generated for each user and combined with their password before hashing. Because every user has a unique salt, attackers cannot use precomputed tables and must crack each password individually from scratch.

Secure Password Storage and Verification Pipeline with Argon2id

1. User Submits Password
The user creates an account and enters a passphrase over an encrypted TLS connection
2. Generate Random Salt
The server creates a unique, cryptographically random 16-byte salt for that specific user
3. Slow Memory-Hard Hash
The server hashes the password and salt using Argon2id, allocating memory (such as 64 MB) to prevent GPU cracking
4. Store Hash String
The server stores the resulting hash string, which contains the algorithm, memory cost, salt, and digest
5. Login Comparison
When the user logs in, the server re-hashes the input using the stored salt and compares the two using a constant-time check

Key Points

  • Never store plaintext passwords or use fast hashing algorithms like MD5 or SHA-256 for passwords.
  • Argon2id is the modern industry standard for password hashing because of its memory hardness.
  • Salts must be unique for each user to prevent attackers from using precomputed rainbow tables.
  • Password length provides much greater security than complicated character requirements.
  • Security standards like NIST SP 800-63B advise against mandatory periodic password resets because they lead to weak variations.

Steps

  1. Use a Password Manager

    Use a password manager (like Bitwarden or 1Password) to generate and remember unique, long passwords for every account.

  2. Prioritize Length Over Arbitrary Symbols

    Follow modern guidelines (like NIST SP 800-63B): encourage longer passphrases rather than forcing frequent password changes or strange character combinations.

  3. Use Argon2id or bcrypt in Backend Code

    Always hash user passwords with modern algorithms like Argon2id or bcrypt with an appropriate work factor (such as 12).

  4. Use Constant-Time Comparison

    Compare password hashes using constant-time comparison methods (`crypto.timingSafeEqual`) to prevent timing side-channel attacks.

  5. Check for Known Compromised Passwords

    Screen new user passwords against known breach databases (using services like Have I Been Pwned) so users avoid already-leaked passwords.

Examples

The Speed Bump Analogy

Hashing passwords with fast algorithms like SHA-256 is like giving a car a wide, flat highway: an attacker's computer can test billions of passwords per second. Using a memory-hard algorithm like Argon2id is like putting large speed bumps on that road: each guess requires real memory and processor time, slowing the attacker down dramatically while legitimate users barely notice a tiny fraction-of-a-second delay during login.

Real-World Examples

The LinkedIn Password Leak (2012 / 2016)

Attackers breached LinkedIn and downloaded over 100 million user credentials. Passwords had been stored using unsalted SHA-1 hashes. Because SHA-1 is extremely fast and lacked salts, researchers and attackers were able to crack over 90% of the passwords within days using precomputed rainbow tables and graphics cards.

The Adobe Password Breach (2013)

Adobe suffered a breach that exposed over 150 million records. Instead of using one-way hashing, passwords were encrypted symmetrically using 3DES in ECB mode. Because identical passwords created identical encrypted blocks, attackers easily mapped out popular passwords and decrypted millions of accounts.

Technical Examples

Hashing and Verifying Passwords with Argon2id in Node.js / TypeScripttypescript
import argon2 from "argon2";
import crypto from "crypto";

// ─── 1. SIGNUP: Hash Password with Argon2id ────────────────────────────────
export async function hashPassword(plainTextPassword: string): Promise<string> {
  // Argon2id combines resistance against side-channel and GPU cracking
  const hash = await argon2.hash(plainTextPassword, {
    type: argon2.argon2id,
    memoryCost: 65536, // 64 MB of RAM (slows down GPU parallelization)
    timeCost: 3,       // 3 iterations through memory
    parallelism: 4,    // 4 parallel threads
    hashLength: 32,    // 32-byte digest output
  });

  // Returns formatted string containing version, memory, time, salt, and digest
  return hash;
}

// ─── 2. LOGIN: Verify Password Against Stored Hash ────────────────────────
export async function verifyPassword(plainTextPassword: string, storedHash: string): Promise<boolean> {
  try {
    // argon2.verify extracts parameters and salt from storedHash,
    // re-hashes candidate password, and performs constant-time comparison
    const isValid = await argon2.verify(storedHash, plainTextPassword);
    return isValid;
  } catch (err) {
    return false;
  }
}

// ─── 3. BREACHED PASSWORD CHECK: k-Anonymity API ─────────────────────────────
export async function isPasswordBreached(password: string): Promise<boolean> {
  // Compute SHA-1 hash of password
  const sha1 = crypto.createHash("sha1").update(password).digest("hex").toUpperCase();
  const prefix = sha1.substring(0, 5);
  const suffix = sha1.substring(5);

  // Query HaveIBeenPwned API with only the 5-character prefix (k-Anonymity)
  const response = await fetch(`https://api.pwnedpasswords.com/range/${prefix}`);
  const body = await response.text();

  // Search if suffix exists in returned hash range
  const matches = body.split("\r\n").some((line) => line.startsWith(suffix));
  return matches;
}
This implementation hashes passwords using Argon2id with 64 MB of RAM and 3 iterations, making automated cracking impractical. It also checks new passwords against Have I Been Pwned using k-Anonymity, verifying passwords against known leaks without ever exposing the user's full password.

Fast Hash (SHA-256 / MD5) vs Slow Memory-Hard Hash (Argon2id / bcrypt)

AspectFast Hash (SHA-256 / MD5)Slow Memory-Hard Hash (Argon2id / bcrypt)
Intended PurposeFile integrity, digital signatures, checksumsPassword storage and credential verification
GPU Cracking SpeedHundreds of billions of guesses per secondA few hundred guesses per second, drastically slower
Adjustable CostFixed speed; cannot be adjusted as computers become fasterConfigurable; work factor can be scaled up over time
Memory UsedAlmost no memory required (easy to run in parallel on chips)Requires megabytes of RAM, limiting parallel hardware attacks
Recommended for PasswordsInsecure and dangerous for passwordsModern industry standard

Advantages

  • Protects Leaked Databases: If a database is stolen, strong password hashing ensures accounts cannot be quickly cracked.
  • Scalable Defense: Cost factors can be increased over time as computer processors get faster.
  • Stops Precomputed Attacks: Unique cryptographic salts prevent attackers from using precomputed rainbow tables.

Limitations

  • Server Resource Usage: Hashing takes a fraction of a second of CPU time and memory, which requires planning on high-volume login servers.
  • Phishing Vulnerability: Password hashing protects stored passwords, but cannot stop an attacker if a user types their password into a phishing site.

Interview Questions

Why is Argon2id preferred over bcrypt and PBKDF2 for password hashing?

PBKDF2 uses processor cycles but almost no memory, which means custom chips (ASICs) and graphics cards (GPUs) can compute millions of guesses simultaneously. bcrypt uses 4 KB of memory, which was strong in the past but now fits easily inside GPU memory caches. Argon2id is memory-hard: it intentionally uses tens of megabytes of RAM per calculation. Because graphics cards have limited fast memory per core, Argon2id saturates memory bandwidth, making large-scale parallel cracking attempts impractical.

How does k-Anonymity allow secure checking of leaked passwords?

Under k-Anonymity, the client hashes the password locally and sends only the first 5 characters of the hash to the checking service (such as Have I Been Pwned). The service returns a list of hundreds of breached hashes that start with those same 5 characters. The client then checks locally whether its remaining hash characters are in that list. The service never receives the full password or full hash, keeping the user's password private.

Practice Questions

  1. Compare the difficulty of guessing an 8-character password with letters, numbers, and symbols versus a 20-character passphrase made of four random words.
  2. Write a small script in your preferred language to measure how long bcrypt takes with different cost factors (such as cost 10 vs 12).