How Two-Factor Authentication Protects Your Account
In this article
Two-factor authentication works by generating a six-digit code that changes every 30 seconds, derived from a secret shared between your account and your authenticator app, using a standard algorithm called TOTP. Neither your password nor a code alone is enough to log in once it's enabled — both are required. This article covers exactly how the code generation works, what the backup codes are for, and what setting up 2FA actually changes in your account.
The Standard Behind the Six-Digit Code
The codes are generated using TOTP (Time-based One-Time Password), the same widely used standard behind most authenticator apps, defined in a public technical specification (RFC 6238) rather than being a custom or proprietary scheme. TOTP itself builds on an older algorithm, HOTP, which generates a code from a secret key and a counter using a cryptographic hash function. TOTP's contribution is using time instead of a manually incremented counter — the current time, divided into 30-second windows, functions as the counter automatically, which is why the code changes on its own every 30 seconds without you or the server needing to track state between requests.
What Happens When You Turn 2FA On
Turning on 2FA generates a random secret — a value derived from cryptographically random bytes, encoded in a format called base32, which is the standard encoding authenticator apps expect for these secrets. That secret is what gets shown to you as a QR code or a manually-typeable string during setup. Scanning it into an authenticator app gives that app the same secret your account has stored, which is what allows both sides to independently compute the same six-digit code at the same moment without ever transmitting the code itself over the network during normal login.
2FA isn't actually active the moment the secret is generated — it only turns on after you confirm setup by entering a code your app just generated, proving the secret was scanned correctly and the app is generating matching codes before the account is locked to requiring it.
Why the Code Works Even Though the Server and Your Phone Never Talk to Each Other
This is the part people sometimes assume requires a live connection, but it doesn't. Because both your phone's authenticator app and the server independently know the same secret and both have access to the current time, they can each compute the same code without any communication between them during the 30-second window it's valid. Your phone doesn't need internet access to generate a valid code — this is why authenticator apps work in airplane mode. The server verifies a submitted code by running the identical calculation itself and checking whether the two match.
What Backup Codes Are For
When you finish enabling 2FA, you're given a set of one-time backup codes, generated once at that moment and never shown again afterward — similar to how an API key value is shown only at creation. These exist specifically for the scenario where you lose access to your authenticator app (a lost phone, a wiped device) and would otherwise be completely locked out, since a password alone is no longer sufficient once 2FA is active. Each backup code is stored on the server as a hash rather than in plain text, the same protective approach used for API keys, so a database exposure doesn't hand out usable backup codes any more than it would hand out usable passwords.
What Disabling 2FA Actually Requires
Turning 2FA off isn't a simple toggle — it requires submitting a valid code first, the same as logging in does. This is a deliberate design choice: if disabling 2FA required nothing more than flipping a setting, anyone who got temporary access to a logged-in session could quietly strip the account's second factor. Requiring a fresh valid code to disable it means the same proof of possession needed to log in is also needed to remove the protection.
Frequently Asked Questions
What happens if I lose my phone and I've used all my backup codes? At that point neither factor is available through normal means, which is the tradeoff of strong two-factor protection — it's designed to be difficult to bypass, including by you. Account recovery in that situation typically requires manual identity verification through support rather than a self-service reset.
Can I use the same authenticator app for multiple accounts? Yes — TOTP is a general standard, and authenticator apps are built to store many independent secrets at once, each tied to a different account. There's nothing account-specific about the app itself; the secret is what makes each entry unique.
Why does the code stop working if my phone's clock is off? Because the code is derived from the current time divided into 30-second windows, both sides need to agree on roughly what time it is. Most authenticator apps sync time automatically, but a phone with a significantly incorrect clock can generate codes the server doesn't recognize as valid, since it's computing against a different time window than the server is.
Related Articles
How the Comment Notification Digest Batches Client Activity Into One Email
Why a burst of client comments produces exactly one email, not five — and how the rolling delay resets on every new comment.
How In-App Notifications Fan Out to Your Team
Why every workspace member gets their own independent notification row, and why you don't get notified about your own actions.
The Invoice Audit Trail: Every Event Logged Behind the Scenes
What actually gets recorded when an invoice is viewed, commented on, or changes status — and why the logging never blocks the action itself.
How API Keys Are Stored (And What to Do If You Lose One)
The raw value of your API key is never stored anywhere after the moment you create it — only a one-way hash is kept, which is why a lost key can't be recovered.
Is It Safe to Put a QR Code on Your Invoice?
If you've thought about adding a QR code to your invoices, you've probably also seen a headline or two about "quishing" — QR code phishing — and wondered whether you'd be handing your clients a security risk along with your bill. That's...
Building Reliable Integrations With Invoice Webhooks
Webhooks look simple from the outside: something happens, you get a POST request, you do something in response. The complexity shows up once you start asking what happens when that POST request doesn't arrive, arrives twice, or arrives w...