Password Authentication: Cryptographic Salting, Peppering & Memory-Hard Hashing
Passwords must never be stored in plaintext or fast hashes. Secure password authentication uses memory-hard algorithms like Argon2id with unique cryptographic salts and optional peppers to protect credentials against offline attacks.
A. Why Storing Plaintext Passwords Is Dangerous
When users register on a website, they trust the application to safeguard their credentials. Unfortunately, database leaks, misconfigured cloud storage, and security breaches happen regularly in the real world.
If an application stores passwords in plaintext (plain, readable text like "mypassword123"), anyone who gains unauthorized access to the database immediately sees every user's password. Because many people reuse passwords across personal email, banking, and social media accounts, a single plaintext database breach can compromise a user's entire digital identity.
Storing passwords in plaintext is like writing the PIN code to your home on a sticky note and pasting it to the front door. Secure password hashing transforms that secret into a permanent, scrambled digital lock that cannot be reversed.
B. What Is Password Hashing?
To protect passwords, applications use a one-way cryptographic hash function. Here is how the key terms connect:
The raw text the user typed on their keyboard. This must never be stored in the database.
A specialized mathematical algorithm that takes input data and produces a scrambled, fixed-length output string.
The scrambled string stored in the database. It is safe to store because it cannot be turned back into the password.
Encryption is two-way: data is scrambled, but can be decrypted using a secret key. Hashing is strictly one-way: there is no key that can unhash the string.
C. Understanding Salt and Pepper
If you only hash the raw password, an attacker can spot patterns: identical passwords produce identical hashes. Two techniques protect against this:
1. Cryptographic Salt
A salt is a unique, cryptographically random string generated automatically for each user upon signup.
Important: Salts are not secret. They are stored right next to the hash in the database. Their purpose is uniqueness: ensuring that two users with the same password have completely different hashes.
2. Secret Pepper
A pepper is an application-wide secret value added to passwords before hashing.
Important: Peppers must be kept strictly secret. They are stored separately from the database (e.g., in a secure secret manager or environment variable) to provide defense-in-depth if the database is leaked.
| Feature | Cryptographic Salt | Secret Pepper |
|---|---|---|
| Scope | Unique for every single user | Shared across the entire application |
| Where Stored | In the database alongside the hash | Stored separately (Secret Manager / Env Var) |
| Confidentiality | Public (does not need to be secret) | Strictly confidential and secret |
| Primary Purpose | Stops precomputed lookup tables & identical hashes | Protects hashes if the database file is stolen |
Password Security Lab: 3 Key Experiments
If two users choose the exact same password, will their stored hashes look identical? Observe how adding a unique random salt ensures two completely distinct hash strings.
Alice and Bob share the exact same password, but their stored hashes look completely unrelated. An attacker who steals the database cannot tell that they share the same password, and precomputed lookup tables are completely neutralized.
D. Why Not Use SHA-256 for Passwords?
General cryptographic hash functions like SHA-256 and MD5 were engineered for speed. They are designed to verify large files, verify data integrity, and sign certificates in fractions of a microsecond.
Because fast algorithms run in nanoseconds, attackers can test millions of password guesses very quickly using modern hardware. For password storage, we need the exact opposite: deliberately slow and resource-intensive algorithms.
The modern standard for password hashing. It is memory-hard, requiring both CPU time and physical RAM.
A reliable, battle-tested standard that uses a configurable work factor to increase computation time.
A standardized legacy option based on repeated hashing iterations. Slower than SHA-256, but lacks memory-hardness.
E. Understanding Argon2id
Argon2id is currently recommended by security standards because it is memory-hard. It gives engineers three simple tuning knobs:
How much RAM is required to compute one hash (e.g., 64 MB). Requiring physical memory makes mass parallel guessing impractical.
How many computational passes the algorithm performs over the memory, scaling calculation time linearly.
How many independent CPU threads cooperate to compute the hash on multi-core processors.
Guidance for engineers: Parameters should be chosen based on server capacity and current security guidance (e.g. OWASP recommendations), rather than treated as a fixed universal guarantee.
F. Registration and Login Workflow
User Registration (Storing the Password)
Create Password
User creates a password on the signup form.
Generate Salt
Server generates a unique random salt.
Generate Hash
Password-hashing library generates the password hash.
Store in Database
Hash and required parameters are safely stored in the database.
User Login (Verifying the Password)
Submit Password
User submits password on the login form.
Retrieve Hash
Server retrieves the stored hash from the database.
Library Verifies
Password-hashing library verifies the submitted password.
Result Rendered
Login succeeds (200 OK) or fails (401 Unauthorized).
H. Knowledge Check
Test your understanding with these 4 quick conceptual questions. Click an answer to check yourself!
Why should passwords NEVER be stored in plaintext inside a database?
What is the primary purpose of adding a unique cryptographic salt to each user password?
Why are fast cryptographic algorithms like SHA-256 unsuitable for storing user passwords?
True or False: A password salt must be kept strictly secret and hidden from the database.