Skip to content
Engyna

Privacy & security

How Two-Factor Authentication Works (and Which Type to Use)

What really happens behind those six-digit codes, how SMS, authenticator apps, security keys and passkeys compare, and how to avoid locking yourself out.

Updated · 5 min read

Passwords leak all the time, through breaches at companies you've long forgotten, through phishing and through malware. If someone has your password and nothing else protects your account, they're in. Two-factor authentication, or 2FA, adds a second check, so the password on its own is no longer enough.

The idea behind it

Authentication factors fall into three groups:

  • Something you know, such as a password or PIN
  • Something you have, such as a phone or a security key
  • Something you are, such as a fingerprint or your face

Two-factor means using two different groups. A password plus a security question isn't real 2FA, as both are things you know. A password plus a code from your phone is, since an attacker would need to steal both.

How the six-digit codes work

The codes from an authenticator app seem like magic, because they work with no internet connection. They come from an open standard called TOTP (time-based one-time password, RFC 6238).

  1. Setup. The website generates a random secret, and shows it to you as a QR code. Your app stores it, and the website keeps a copy.
  2. Generating. Your app takes the secret and the current time, rounded to a 30-second step, and runs them through a hash function.
  3. Checking. The website does the same calculation. If both results match, you're in.

No code ever travels between your phone and the server until you type it in. Both sides simply do the same math. That's why your phone's clock needs to be right, and why codes change every 30 seconds.

You can see this for yourself with the 2FA code generator, using a test secret. It's a useful way to check a setup, or to find out why a code is being refused.

The types of 2FA compared

Method Security Convenience Weak spot
SMS code Basic High SIM swapping, phishing
Email code Basic High Only as safe as your mailbox
Authenticator app Good Good Phishing in real time
Push approval Good High Accidental approvals
Security key Very high Medium Losing the key
Passkey Very high High Needs account recovery

SMS codes

SMS is the most common type, and it's far better than no 2FA. But messages can be intercepted, and attackers can talk a phone company into moving your number to their SIM card, which is known as SIM swapping. If you have the option, use something stronger for key accounts.

Authenticator apps

These work offline, and the codes aren't sent over the phone network. They're a good default. Their weakness is phishing: a fake login page can ask for your code, and pass it to the real site within seconds.

Security keys and passkeys

Hardware keys and passkeys use public key cryptography, and they're tied to the real website's address. So a fake site can't get a usable answer from them, even if you're fooled. That's why they're considered resistant to phishing.

A passkey replaces the password entirely. Your device holds a private key, which you unlock with your fingerprint, face or PIN. They're increasingly supported by big services, and are worth turning on where they're offered.

How to set it up

  1. Go to your account's security settings.
  2. Turn on two-step verification, or 2FA.
  3. Scan the QR code with an authenticator app.
  4. Type in the code to confirm it.
  5. Save the backup codes.

Start with the accounts that matter most: your email first, as it can reset every other password. Then your password manager, your bank, your cloud storage and social media.

Don't lock yourself out

This is the most common real-world problem with 2FA. If your phone breaks, the codes go with it, unless you've prepared.

  • Save backup codes. Print them, or keep them in a safe place that isn't your phone.
  • Keep the setup key. Some services show the secret as text. A second copy lets you restore your codes.
  • Use an app with secure backup or sync, if it suits you.
  • Register a second factor, such as a spare security key or another phone.
  • Move your codes before you wipe your old phone. Don't reset it until the new one works.

If codes are rejected

The usual reason is a wrong clock. As TOTP depends on the time, a phone that's a minute out can create invalid codes. Set the time and time zone to automatic.

Other causes are scanning an old QR code, or having several entries for one account in your app. The 2FA tool can check a code against the time periods on either side of the current one, which helps you to spot a clock problem.

Keep your secret safe

The setup key is as sensitive as a password, since anyone who has it can generate your codes. Don't send it in chat, don't keep a screenshot of the QR code in a shared folder, and treat exported code lists like passwords.

2FA doesn't replace a good password

Your password still matters. Use a different, long one for each account, ideally from a password manager. The password generator can create one, and the strength checker shows how well a password would hold up.

Stay alert to attacks

Attackers know about 2FA, and try to get around it.

  • Nobody legitimate will ask you for a code. If someone calls and asks you to read one out, it's a scam, even if they claim to be from your bank.
  • Push fatigue. If approval requests pop up that you didn't trigger, someone has your password. Deny them, and change the password.
  • Check the address before entering a code on any login page.

Is it worth the hassle?

Yes. It adds a few seconds at login, and many services only ask on new devices. In return, the most common kind of account takeover, using a stolen password, stops working. Turn it on for your email today, and work through your other accounts from there.