Cryptographic Hash Functions for Password Storage
You'll learn how one-way hash functions transform passwords into irreversible digests, and why general-purpose algorithms like SHA-256 aren't secure enough for protecting user credentials.
What Is a Cryptographic Hash Function?
A cryptographic hash function is a mathematical algorithm that transforms any input (like a password) into a fixed-size string of characters called a "digest" or "hash." Think of it like a meat grinder: you can turn a steak into ground beef, but you can't reconstruct the original steak from the ground meat. This one-way property is crucial—even knowing the hash output, an attacker cannot reverse-engineer the original password.
When a user creates an account, you hash their password and store only the hash. When they log in, you hash their input and compare it to the stored hash. If they match, the password is correct.
Why SHA-256 Alone Is Insufficient
SHA-256 (and other general-purpose hash functions) were designed for speed—to quickly verify file integrity or create digital signatures. But for password storage, speed becomes a vulnerability:
- Brute-force attacks: Attackers can try billions of password guesses per second using modern GPUs
- Rainbow tables: Pre-computed tables of common passwords and their SHA-256 hashes let attackers instantly crack millions of passwords
- No built-in salt: SHA-256 alone doesn't force unique hashes for identical passwords across different users
Even with a unique salt (random data added to each password before hashing), SHA-256 remains too fast. Attackers can still test millions of guesses quickly once they obtain your database.
Key Takeaway: While SHA-256 is a strong cryptographic hash, its speed makes it unsuitable for password storage—you need specialized, intentionally slow algorithms designed to resist modern cracking techniques.