Lesson 1 · Unit 01
Hashes
Fingerprints, salts and why password hashes must be slow
What you practise
- One-way and deterministic, collisions, checksums vs cryptographic hashes
- Storing passwords: salts, why fast hashes are wrong, bcrypt/argon2, rainbow tables
Try a question from this lesson
Pick one
A site stores a hash of your password, never the password itself. A hash cannot be reversed. So how does it check what you type at login?
Correct answer
It hashes what you typed and compares the two hashes
Why
The same input always gives the same hash, so the site never needs the original: it hashes your attempt and compares. Nothing is decrypted, because a hash has no key and no way back.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
A hash is a fingerprint
A hash function turns any input into a fixed-size value.
It is deterministic: same input, same hash. It is one-way: you cannot compute the input from the hash. And one changed character gives a completely different result.
SHA-256 always produces 256 bits, written as 64 hex characters.
import hashlib
h = hashlib.sha256(b"hello").hexdigest()
print(len(h), h[:8]) # 64 2cf24dbaConcept
Salt: random bytes per user
A salt is a random value created for each user and stored next to their hash. The server hashes salt + password.
Two users with the same password now get different hashes, and a precomputed table is useless: the attacker must start over for every single user.
The salt is not a secret. Its job is to be different for everyone.
import hashlib, secrets
salt = secrets.token_bytes(16)
h = hashlib.sha256(salt + b"hunter2")
record = (salt.hex(), h.hexdigest())10 more exercises in the app
- 2× type the answer
- 2× true or false
- 4× multiple choice
- 1× fill the blanks
- 1× match the pairs
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.