Chrysolites Open Courses

Cybersecurity from the Ground Up · Course book

Chapter 1: Securing Accounts and Data

Pairs with Lesson 1: Harvard CS50: Securing Accounts, Data and Systems

Most security incidents that affect ordinary people do not begin with a brilliant hacker breaking strong encryption. They begin with a reused password, a lost laptop, an unpatched phone or a message that persuades someone to type their details into the wrong page. This chapter starts where those incidents start: with accounts and the data behind them. It explains how authentication works and why some methods are stronger than others, measures password strength with simple arithmetic, shows how well-run services store passwords so that a stolen database is less useful to an attacker, and describes how encryption protects data on devices and as it travels. Throughout, the guiding idea is the one that runs through the whole course: security is rarely absolute. It is a trade-off between the cost and effort an attacker must spend, the cost and inconvenience you accept, and the value of what is being protected.

Authentication: proving who you are

Every account has two steps. Identification is claiming an identity, such as typing a username or email address. Authentication is proving that claim. Systems can ask for three kinds of evidence, usually called factors: something you know, such as a password or PIN; something you have, such as a phone, a hardware security key or a bank card; and something you are, such as a fingerprint or face. Once you are authenticated, a separate step called authorisation decides what you are allowed to do, which is why a logged-in student and a logged-in teacher see different options in the same school system.

A single factor can fail. Passwords are guessed, phished or leaked; phones are stolen; fingerprints can occasionally be fooled. Multi-factor authentication (MFA) asks for two or more factors of different kinds, so an attacker who steals one still lacks the other. Two passwords are not MFA, because both are the same kind of factor and can be stolen in the same way.

Something you knowpassword, PIN Something you havephone, security key Something you arefingerprint, face Access grantedtwo different factors = MFA
Figure 1.1 — The three kinds of authentication factor. Multi-factor authentication combines factors of different kinds, so stealing one is not enough.

MFA methods differ in strength. Codes sent by text message are better than nothing but can be intercepted or redirected if an attacker persuades a mobile network to move your number to a new SIM card. Codes from an authenticator app are stronger because they are generated on the device itself. Strongest of all for most people are passkeys and hardware security keys, which use public-key cryptography and are tied to the genuine website's address, so they will not work on a look-alike phishing page even if the user is fooled.

How strong is a password?

An attacker who has no other information must guess. The number of possible passwords is the size of the alphabet raised to the power of the length. A four-digit PIN has 104 = 10,000 possibilities. A password of eight lower-case letters has 268, about 209 billion. Security professionals express this as entropy in bits: the number of times you would have to double 1 to reach the number of possibilities. Each extra bit doubles the attacker's work.

Password made ofPossibilitiesEntropy (bits)
4 digits (PIN)10,00013.3
8 lower-case lettersabout 2.1 × 101137.6
8 characters from 94 printable symbolsabout 6.1 × 101552.4
12 characters from 94 symbolsabout 4.8 × 102378.7
4 random words from a 7,776-word listabout 3.7 × 101551.7
6 random words from a 7,776-word listabout 2.2 × 102377.5
Worked example. Suppose an attacker has stolen a password database and can test 10 billion (1010) guesses per second against a weak, fast hash. Eight random lower-case letters give about 2.09 × 1011 possibilities, so trying them all takes 2.09 × 1011 ÷ 1010 ≈ 21 seconds. Eight characters from all 94 printable symbols give about 6.1 × 1015, which takes about 6.1 × 105 seconds, roughly 7 days. Twelve characters from 94 symbols give about 4.8 × 1023, about 4.8 × 1013 seconds, which is more than 1.5 million years. On average an attacker finds a password halfway through, but halving does not change the picture.

These numbers apply only to passwords chosen at random. Human-chosen passwords such as Summer2024! follow predictable patterns, and attackers try common words, names, dates and known leaked passwords first, so such a password may fall in seconds whatever its length. That is why the practical advice is: use a password manager to generate and store a different random password for every account, or a passphrase of several randomly chosen words for the few you must remember. Reuse is the most dangerous habit, because a leak from one small website lets attackers try the same email and password on banks, email providers and social networks, an attack known as credential stuffing.

lower-case only 94 symbols 1 s1 day1 yr1,000 yr10⁶ yr 68101214 password length (characters)
Figure 1.2 — Time to try every random password at 1010 guesses per second (logarithmic scale). Each extra character multiplies the work by the size of the alphabet, so length and variety both matter.

Storing passwords safely: hashing and salting

A responsible service never stores your password itself. Instead it stores a hash: the output of a one-way function that turns any input into a fixed-length string. When you log in, the service hashes what you typed and compares the result with the stored hash. If the database is stolen, attackers get hashes, not passwords, and must guess inputs until one produces a matching hash.

Two refinements make that guessing much harder. A salt is a random value stored alongside each user's hash and mixed into the input before hashing. Because every user has a different salt, two people with the same password get different hashes, and attackers cannot use a precomputed table of hashes for common passwords; they must attack each account separately. Second, good systems use deliberately slow password-hashing functions, such as bcrypt, scrypt or Argon2, which can be tuned so each guess takes, say, a tenth of a second instead of a billionth. That barely affects a real user logging in once, but it divides an attacker's guessing rate by many millions. In the worked example above, a twelve-character random password was already safe; with a slow hash, even an eight-character random password would take far longer than any realistic attack.

Hashing is not the same as encryption. Encryption is designed to be reversed by someone holding the key; hashing is designed never to be reversed at all. Passwords should be hashed. Data that you need to read back later, such as files and messages, should be encrypted.

Protecting data at rest and in transit

Data is said to be at rest when it is stored on a laptop, phone, memory stick or server, and in transit when it travels across a network. Both need protection. Full-disk encryption, now built into most phones and computer operating systems, scrambles everything on the drive with a key that is unlocked only by your PIN, password or biometric. A stolen laptop with full-disk encryption and a strong login reveals nothing useful; without it, anyone can remove the drive and read the files directly.

In transit, the padlock symbol and the https prefix in a browser's address bar indicate TLS (Transport Layer Security), which encrypts the connection between your device and the website and lets your browser check the site's certificate. TLS stops people on the same café Wi-Fi from reading your traffic, but it does not prove that the website is honest; a phishing site can have a valid certificate too. Some messaging apps go further with end-to-end encryption, in which only the sender's and recipient's devices hold the keys, so even the service provider cannot read the messages.

Encryption protects confidentiality, but data can also be lost. A device can fail, be stolen or be locked by ransomware. Backups protect availability. A widely used rule of thumb is 3-2-1: keep at least three copies of important data, on two different kinds of storage, with one copy off-site or offline. Deleting data securely matters too: ordinary deletion often only removes the file's entry from an index, which is why encrypted drives, or a proper erase function, should be used before a device is sold or recycled.

Security as a trade-off

It would be possible to make any account extremely secure by requiring a fresh 30-character password, a hardware key and a fingerprint at every login. Nobody would use it. Security always competes with usability, and the right level depends on what is at stake. A sensible way to decide is to ask four questions: what am I protecting, who might want it, how could they get it, and what would it cost me to stop them? Your main email account deserves particular care, because it can usually reset the passwords of every other account. A forum account that holds nothing personal deserves much less.

Thinking from the attacker's side helps. Most attackers are not targeting you personally; they run automated campaigns and move on to easier victims when an account resists. A unique random password and app-based MFA defeat the overwhelming majority of such attacks for very little effort. The aim is not to be unbreakable but to make yourself a poor return on the attacker's investment, while keeping your own costs in time, money and frustration reasonable.

Check your understanding

  1. Explain the difference between identification, authentication and authorisation, using a school or workplace login as an example.
  2. Why is entering two passwords not multi-factor authentication? Give one genuine two-factor combination.
  3. Calculate the number of possible six-digit PINs and the time to try them all at 1,000 guesses per second.
  4. A password has 16 characters chosen at random from the 26 lower-case letters. Is its entropy higher or lower than 12 characters from 94 symbols? Show your working using the fact that each lower-case letter adds about 4.7 bits and each symbol about 6.55 bits.
  5. Describe what a salt is and which attack it prevents.
  6. Your laptop holds coursework, family photos and saved passwords. Design a 3-2-1 backup plan for it.

Install Chrysolites Open Courses

Android / Chrome / Edge: open the browser menu and choose Install app or Add to Home screen.

iPhone / iPad (Safari): tap the Share button, then Add to Home Screen.