Please enable JavaScript to use CodeHS

Cybersecurity Basics

What Is Two‑Factor Authentication?

A password is one lock on your account. Two-factor authentication adds a second lock, so a stolen password alone isn't enough to get in. Learn how it works, then try logging in yourself.

Security ~9 min Middle / High school
The Big Idea

Why passwords aren't enough

A password feels like a good lock. You pick a secret word or phrase, and only you know it. But passwords leak more often than you'd think, in a few different ways.

  • Data breaches: A website you use gets hacked, and a giant list of usernames and passwords gets stolen all at once — sometimes millions of them.
  • Guessing: Attackers try common passwords, birthdays, or pet names, and computers can try thousands of guesses per second.
  • Reused passwords: If you use the same password on multiple sites and just one of them leaks, an attacker can try that same password everywhere else you have an account.

Here's the scary part: on most accounts, a correct password is the only thing standing between an attacker and your data. If they get it — any way at all — they're in.

Two-factor authentication (2FA) fixes this by requiring a second, separate proof of who you are before letting anyone log in — even if they already typed the correct password.


How It Works

How 2FA works

Security experts group every way of proving who you are into three categories, sometimes called "factors." 2FA works by combining two of them.

Something you know

A password or PIN. Anyone who learns it can use it — that's the weak point.

Something you have

Your phone, a security key, or an ID card. Hard to steal from far away.

Something you are

Your fingerprint or face. It's part of you, so it's very hard to copy.

Most 2FA pairs your password (something you know) with a code sent to your phone (something you have). Think of it like a bank vault that needs both a key and a fingerprint scan to open. Stealing the key isn't enough on its own — the thief would still need your fingerprint too.

That's the whole trick: 2FA doesn't make your password stronger. It just makes the password useless on its own, because the attacker also needs something they almost certainly don't have.


Interactive

Try it: login simulator

Below is a mock login form — the username and password are already filled in for you, just to show what a normal login looks like. Click Log In and see what happens next. Then switch to the "hacker" scenario and try to get past step two using only the stolen password.

Login simulator


Compare

Types of 2FA

Not all second factors are equally strong. Here are the three most common kinds you'll run into, from weakest to strongest.

Weaker

SMS text codes

A code arrives as a text message. It's convenient and works on any phone, but attackers can sometimes redirect your phone number to their own device through a trick called a SIM-swap scam, letting them receive your codes.

Stronger

Authenticator apps

An app on your phone (like Google Authenticator or Authy) generates a fresh code every 30 seconds. It doesn't rely on the cell network at all, so it can't be stolen with a SIM-swap.

Strongest

Hardware keys & biometrics

A physical security key you plug in or tap, or your fingerprint/face built into your device. These are the hardest to fake or steal remotely, which is why banks and companies use them for their most sensitive accounts.


Your Turn

Check your understanding

In your own words: why doesn't a stolen password alone let an attacker into a 2FA-protected account?

Your answer:

Sample answer: Because the account also requires a second proof, like a code sent to the owner's phone. The password only proves "something you know." Without the phone, the attacker is missing "something you have," so the login stops at step two.


Check Yourself

Quick quiz

1. What are the three categories of authentication factors?

2. Why does 2FA stop an attacker who only has your stolen password?

3. Which pairing is correct?

Keep learning about cybersecurity

You've seen how a second lock keeps your accounts safe even when a password leaks. Next, learn about the malicious software attackers use once they do get access to a device.

Part of the Cybersecurity Basics tutorial series.