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 an Invoice Is Stored: One Row per Line Item, Plus a Full Copy
A saved invoice is stored as one database row per line item, linked by a shared group ID, with a full copy of the invoice on every row. Saving an edit replaces all of those rows in one transaction.
Why Sign-In Attempts Are Rate Limited
Sign-in, sign-up, two-factor checks, and verification resends share a budget of 10 attempts per hour per IP address, which is much stricter than the limit on ordinary app requests. Here's why the numbers differ.
How Sign-Up and Email Verification Actually Work
Creating an account sets up a personal workspace in the same database transaction, the verification link lasts 24 hours, and clicking an expired one quietly sends you a fresh link instead of leaving you stuck.
How Your Logo Gets Stored When You Upload It
A logo pasted in as a remote URL gets fetched server-side, checked against a 2MB cap and a real image content type, and converted into a self-contained data URL before it's saved.
Why You Get Logged Out After an Hour
Every session token expires in exactly one hour, and there's no refresh mechanism behind the scenes extending it quietly — plus the one deliberate exception carved out for two-factor logins.