Unit 7: Online data security · User authentication methods

Article

Strong passwords

8 min read

A password is a lock on your account. A weak lock is worse than none, because it makes you feel safe. What makes a password strong? Two things: it is long, and it is hard to predict.

How attackers guess

An attacker does not sit and type. A program tries guesses very fast, perhaps a billion a second. It guesses in two ways:

  1. Try everything. Every combination in turn. This is the brute-force attack from the encryption lesson.
  2. Try the likely ones first. Common passwords, names, birthdays, pet names, and words from a dictionary. People pick these all the time, so they fall in seconds.

Length beats the first way. Being unpredictable beats the second.

Counting passwords

Say a password has n characters, and each one comes from a set of k possible characters. The number of possible passwords is kⁿ. The 26 lowercase letters give k = 26. Lowercase, uppercase and digits give 26 + 26 + 10 = 62. Run this and change length:

Runs in your browser

Python's ** means "to the power of". Now the times, if an attacker tries a billion guesses every second:

Length26 characters62 characters
6308,915,776 (0.3 seconds)about 56.8 billion (57 seconds)
8about 209 billion (3.5 minutes)about 218 trillion (2.5 days)
10about 141 trillion (1.6 days)about 8.4 × 10¹⁷ (27 years)
12about 9.5 × 10¹⁶ (3 years)about 3.2 × 10²¹ (100,000 years)

Look at two rules hiding in the table:

  • One more character multiplies the count by k. With 26 characters, 9 letters allow 26 times more passwords than 8 letters.
  • A bigger character set helps, but length helps more. 12 lowercase letters allow about 437 times more passwords than 8 characters from all 62.

This is the same unreasonable-time idea as before. Each extra character multiplies the attacker's work.

Check your understanding

A password has 3 characters, and each character is a lowercase letter (26 choices). How many different passwords are possible?

Easy to remember, hard to guess

A password like maya2009 is easy to remember but it is a name and a year, exactly what attackers try first. Swaps such as P@ssw0rd are well known too. Random characters like x7Kq!9mZ are hard to guess but hard to remember, so people write them down or reuse them.

The best answer is a passphrase: several random words, like lamp-river-orange-seven-cloud. Choose the words by chance (dice or a generator), not from a song or a saying. If the word list has 2,000 words, five random words give 2,000⁵ = 3.2 × 10¹⁶ passphrases. That is more than 100 times as many as 8 random characters from 62, and a person can remember it.

Never reuse a password

Websites get hacked. If you use one password everywhere, the attacker takes the one stolen from the weak site and tries it on your email, your bank and your games. Use a different password for every account.

You cannot remember dozens of long passwords. A password manager can: it stores them in an encrypted vault, makes long random ones for you, and fills them in. You remember only one strong passphrase to open the vault. It also helps against fake sites, because it fills a password only on the real address.

How a site should store your password

A well-run site never keeps your password as plain text. If it did, a thief who stole the database would see everyone's passwords. Instead the site keeps a scrambled form, made by a one-way method (often called a hash). It is not encryption, because there is no key and no way to get the password back. The code below isn't tested on the exam. Run it to see the idea:

Runs in your browser

The same password always gives the same scramble, but a tiny change gives a completely different one.

Checking a login

  1. You type your password

    scramble
  2. The site scrambles it

    the same way as when you signed up

    compare
  3. The site compares it with the stored scramble

    match?
  4. Same? You are in

The real password is never stored. Even so, a weak password can be found if a thief scrambles common guesses and compares them, so a strong password still matters.

Check your understanding

How should a well-run website store your password?

Worked example

A site lets you use 8 characters. At first it allows lowercase letters only (26). Then it also allows digits (36 characters). How many times more passwords are possible?

  1. Before: 26⁸ = 208,827,064,576.
  2. After: 36⁸ = 2,821,109,907,456.
  3. Divide: 2,821,109,907,456 ÷ 208,827,064,576 is about 13.5.

Compare adding a ninth lowercase letter instead: that gives 26 times more. Length wins again.

Common mistakes

  • "A symbol swap makes it strong." P@ssw0rd is on every attacker's list.
  • "Longer always means stronger." passwordpassword is long and predictable.
  • "I'll just add a number to the old one." maple1, maple2... is easy to guess once one leaks.
  • "A hash is encrypted, so it can be decrypted." A hash has no key and cannot be reversed.
  • "My password is safe because the site stores it scrambled." Weak passwords can still be guessed from the scramble.

On the exam

Questions give you passwords and ask which is strongest (long, random, not personal, not reused), or ask "How many times more passwords are possible if…". Work out kⁿ before and after, then divide. Remember the CED's phrase: strong passwords are easy to remember but hard to guess.

Key words

Authentication: proving you are who you say you are.

Password: a secret string of characters used to authenticate.

Passphrase: a password made of several random words.

Password manager: a program that stores and fills in strong, different passwords.

Hash: a one-way scrambled form of a password that cannot be turned back.

AP® is a trademark registered by the College Board, which is not affiliated with, and does not endorse, this site. All lessons and questions here are written by JrCodex.