← Security and privacy

Hashes and salt

Good sites never store your password. They store a hash: a one-way scramble that is always the same for the same password, so a login can be checked but the hash can't be turned back. A stolen list can still be cracked by hashing common guesses, unless each person's password gets its own salt.

Websites get hacked and their password lists stolen. If the site did its job, the attackers still don't get your password. How?

A hash protects passwords where they are stored. It turns any text into a fixed-length scramble. The same input always gives the same hash, but there is no way to work backwards from the hash to the input. (Protecting data while it travels is the next lesson.)

How this lesson works: Predict, Try, Investigate, Modify, Practise, Make
PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.

A stolen list

A website is hacked and its list of passwords is stolen. If the site did its job properly, what do the attackers find for your account?

TryTry it on the board and compare the result with your prediction.

Try: sign in with a hash

Was your prediction right? Watch how many digits change for one letter.

Try it yourselfYour edits are saved in this browser.

The site stores only Kai's hash. Type Kai's password (maple). Then change one letter to a capital. What happens to the hash?

Use the board. This ticks when you get there.

InvestigateWork out why it happens, one step at a time.

Worked example: hashes and salt

Worked exampleBefore each step, say what you think comes next.
  1. maple→49ead2b1066b…\text{maple} \to 49ead2b1066b\ldotsHashing: a fixed-length scramble of the password.

Now explain how a site checks a password.

Why can a site check your password without storing it?

Sam explains how Forgot password works. Click the line where it first goes wrong.

Ana and Ben both use maple. With no salt, a stolen list shows the same hash twice. What does that tell a thief?

ModifyChange the problem on purpose and see what happens.

Vary: crack a list, then salt it

Need a hint?

Before a hint: what kind of stuck is this? Try a strategy first

Think of passwords people pick a lot.

Another hint

Try a word you've seen in this lesson.

Another hint

maple.

Try it yourselfYour edits are saved in this browser.

This list was stolen from a site with no salt. Type passwords people often pick, one at a time, and watch for a row lighting up.

Use the board. This ticks when you get there.

Type maple, then switch on the salt. Ana and Ben both use maple. Are their hashes the same?

Use the board. This ticks when you get there.

PractiseA few on your own, to check you have it.

Hashes

A site emails you your old password when you click Forgot password. What does that tell you?

Why are long passphrases safer even when sites store hashes?

Which tool fits? Sort each one.

A site keeps your password so it can check it next time
Your card number on its way to an online shop
Checking a downloaded app is exactly the file its maker published
A private message to a friend across the internet
A news headline anyone can read

Review: which is authorisation?

MakeMake your own problem using what you have learned. Expect a few tries; that is normal.

A strong passphrase

Then: why should you never use the same password on two sites, even a strong one?

Try it yourselfYour edits are saved in this browser.
Need a hint?

Before a hint: what kind of stuck is this? Try a strategy first

Use four or more words that don't go together.

Another hint

Separate them with spaces or hyphens.

Another hint

Aim for 20 characters or more. Don't use a real password here.

Make up (don't use a real one) a passphrase of at least four unrelated words and 20 characters. Watch its hash.

Use the board. This ticks when you get there.

Now you can
Next lesson5. Public and private keysTo send a secret to someone you've never met, you can't share a key first: anyone could copy it on the way. Public key encryption works like an open padlock: anyone can lock a message with someone's public key, but only their private key opens it. HTTPS uses it to start every secure connection.
For teachers

Students sign in against a stored hash, see one letter change the whole hash, crack an unsalted stolen list by hashing common guesses, then add a salt, and sort what a hash is for against what encryption is for (AC9TDI10K01 node 4, first half; Public and private keys is the second). About 45 minutes.

Open the teacher guide: answers, solutions, slides and a worksheet.

Students will be able to

Before class

Try the boards yourself. The hash is real SHA-256 (shown short); the passwords in the lesson are practice ones. Tell students never to type a real password into any board.

The kit's typical width: hashing secures stored passwords; public key cryptography (next lesson) secures data in transit; they address different threats, and mixing them up is why this node is a hinge. Split from Hashes and keys on 25 Oct so each gets a full lesson. Simplifications: real sites use slow hashes built for passwords (bcrypt, Argon2) and store the salt beside the hash.

Links: Secret messages' key sharing (agreeing a key in public) is the other half of how HTTPS starts.

Running the lesson

  1. Predict: students who chose "your password" assume sites keep it.
  2. Try: count how many digits changed for one letter.
  3. Worked example: ask why the same password must always give the same hash.
  4. Vary: ask why the thief can crack Ana and Ben without reversing anything; then what the salt changes.
  5. Make: remind students not to type a real password; it is a made-up passphrase.

The hard part (on purpose)

Hashing is one-way, which runs against intuition, and students call it encryption. Use the meat grinder (you can't un-mince) as the anchor, and the sort in Practise to pull hash and encryption apart.

When students get stuck

Stretch and support

Stretch: Why do security experts recommend a password manager? What does it change about using the same password on several sites?

Support: Two cards: Only needs checking → hash (one way). Has to be read again → encryption (a key undoes it).

Where it leads

Next: Public and private keys (protecting data while it travels).

What each step is for