Hashing and Password Storage

Learn what hash functions guarantee, why fast hashes are wrong for passwords, and how salting and slow hashing defeat cracking.

Beginner · about 4 hours · difficulty 2/5

Learn first: Symmetric and Asymmetric Encryption

A hash function turns any input into a fixed-length fingerprint. Good ones are one-way (you cannot reverse them) and collision-resistant (you cannot find two inputs with the same output).

Where hashes are used

  • Integrity: compare the SHA-256 of a download to the published value.
  • Forensics and threat intel: malware is identified by its MD5/SHA-1/SHA-256 hash.
  • HMAC: a keyed hash that proves a message came from someone holding the key (webhooks, API signing).
  • Password storage.

MD5 and SHA-1 are broken for collision resistance; do not use them for security decisions. SHA-256 and SHA-3 are fine for integrity.

Passwords need special hashing

General hashes are designed to be fast, which helps attackers. A GPU can try billions of SHA-256 guesses per second. For passwords use a deliberately slow, salted algorithm: Argon2id (preferred), bcrypt or scrypt.

  • A salt is random per-user data mixed in, so identical passwords produce different hashes and precomputed rainbow tables are useless.
  • A work factor makes each guess expensive.

Cracking (in labs)

Tools like Hashcat and John the Ripper try wordlists and rules against captured hashes. Seeing how quickly weak passwords fall is the best argument for strong hashing and MFA. Only crack hashes you are authorized to test, such as those from CTFs or your own lab.

Pitfalls

  • "Encrypting" passwords so they can be decrypted. Passwords should be hashed, never reversible.
  • Rolling your own scheme like sha256(password + "secret").

Good enough: you can explain salting to a developer and recommend a correct password storage configuration.

Key concepts

  • Hash properties
  • SHA-256 vs broken MD5/SHA-1
  • HMAC
  • Salts and work factors
  • Argon2id, bcrypt, scrypt
  • Hashcat and John in labs
  • Rainbow tables

Mini project

Write a script that stores and verifies passwords with Argon2id or bcrypt, then compare how long Hashcat takes on MD5 versus bcrypt hashes of the same weak passwords in your lab.

Check yourself

Why does adding a unique salt per user defeat rainbow tables but not a targeted guess against one account?

Free resources