Course contentsShow
← Security
Lesson 684 of 3,05215. Web Security - Authentication and SessionsFree lesson

One-Way Hash Functions for Password Storage

Learn why cryptographic hash functions are used for passwords and what makes them irreversible.

One-Way Hash Functions for Password Storage

What you'll learn: How cryptographic hash functions protect passwords by making them mathematically irreversible.


The Core Problem

In the previous lesson, you learned why storing passwords in plain text is catastrophic—anyone who gains database access can read every password instantly. We need a way to verify passwords without storing them. That's where one-way hash functions come in.

What is a Hash Function?

A cryptographic hash function takes any input (like a password) and produces a fixed-size output called a "hash" or "digest." The key property: this process is one-way—you cannot reverse the hash to discover the original password.

Think of it like mixing paint colors. If you combine red, blue, and yellow paint, you get a specific brown color. But if someone hands you that brown paint, you cannot "un-mix" it to determine the exact proportions of red, blue, and yellow that created it.

Why Hash Functions Are Irreversible

Hash functions use complex mathematical operations (bit shifts, modular arithmetic, compression) that destroy information during processing. While the same input always produces the same hash, there's no mathematical way to reverse the computation.

When a user logs in:

  1. You hash their entered password
  2. You compare that hash to the stored hash
  3. If they match, the password is correct

An attacker with database access sees only hashes—not passwords. Without the original password, they cannot log in (assuming strong hashing practices, which you'll learn next).

Common Hash Functions

Examples include SHA-256, SHA-512, and specialized password hashes like bcrypt and Argon2 (which add extra security layers).

Key Takeaway: One-way hash functions transform passwords into irreversible digests, allowing password verification without storing the actual passwords—protecting users even if the database is compromised.