TOTP Generator
You are locked out of a staging environment because your phone died, your QA team needs predictable two-factor codes for automated login tests, or you are migrating a self-hosted authenticator and need the raw secret rendered as working codes. This generator turns any Base32 shared secret into the live time-based one-time passwords that RFC 6238 defines, with the same algorithm Google Authenticator, Authy, and 1Password use.
Paste a secret, watch the current code update every step, and verify any candidate code against the same secret with a configurable clock-skew window. The HMAC work happens through the Web Crypto API inside your tab, so the secret never leaves the machine.
How TOTP generation works under the hood
TOTP is HOTP (RFC 4226) with the moving factor swapped from a counter to the clock. The shared secret is decoded from Base32 into raw key bytes, then the current step counter is computed as the floor of Unix epoch seconds divided by the period, minus the optional t0 epoch from the RFC (zero in practice). That counter is serialized as an unsigned 8-byte big-endian integer and used as the message in an HMAC over the key.
The truncation step takes the last byte of the HMAC digest as a four-byte offset into the digest, clears its high bit to force a positive 31-bit integer, and reduces that number modulo one million (for six digits) or one hundred million (for eight). Modulo is what introduces the slight non-uniformity of leading zeros, which is why some banks dislike very small codes; it has no practical effect on security given the secret entropy.
Servers usually accept codes from the previous, current, and next step so that modest clock drift does not lock users out. The verify panel in this tool applies exactly that window, which is also why a code you saved thirty seconds ago can still validate while the countdown shows a new step has begun.
Before and after: RFC 6238 test vector
Input — the SHA1 test vector from RFC 6238 Appendix B:
secret (ASCII): 12345678901234567890
secret (Base32): GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ
time: 59 seconds after epoch
period: 30
digits: 8
algorithm: SHA1 Output:
counter: floor(59 / 30) = 1
code: 94287082
the same secret with SHA256 at the same instant yields 46119246,
which is why the algorithm selector must match the issuer config Press Load RFC test secret above and the generator reproduces 94287082 only if you also set the time back to the vector instant, but the verify panel accepts it with a widened window from any modern clock for demonstration.
Who uses this generator
Developers
- Write unit tests for your own TOTP implementation by pinning the timestamp and comparing against known RFC vectors instead of guessing expected codes.
- Generate throwaway codes when debugging a CI job that must pass a two-factor gate before the pipeline can deploy.
- Inspect the otpauth:// URI your enrollment screen renders, including the algorithm and digits parameters, without scanning it with a phone camera.
Production
- Recover access to an admin console when the only enrolled device is in a drawer, provided your runbook stores the seed in the secrets manager.
- Seed multiple on-call phones from one stored secret during an incident without waiting for an authenticator transfer flow.
- Confirm a newly deployed identity provider issues codes that match the shared secret before rolling the change to real users.
Workflow
- Move secrets off a personal phone onto a team hardware key or password manager that stores the Base32 seed directly.
- Walk a new hire through enrolling the same secret on their device while you keep a copy in the vault for break-glass access.
- Document the exact digits, period, and algorithm a vendor uses next to the secret so support staff stop guessing during lockouts.
Common mistakes when generating TOTP codes
- Pasting a Base64 or hex string into the secret field. Authenticator seeds are Base32 (A-Z, 2-7). A Base64 secret contains characters like lowercase letters mixed with numbers 0, 1, 8, and 9 that do not exist in Base32, and the generator will reject them rather than produce codes that silently fail at the server.
- Mismatching the digits setting. A server expecting eight digits will reject every six-digit code you submit, even though the underlying HMAC matches. Check the vendor documentation or the otpauth URI parameter rather than assuming six.
- Ignoring clock drift on servers. If a virtual machine clock is minutes off, no code will ever validate because the step counter is computed from wall-clock time. Compare the counter line shown here with the server clock before rotating secrets unnecessarily.
- Using the password, not the seed. The string in your password manager entry labeled password is usually a backup code or the account password. The TOTP seed is the Base32 string shown at enrollment time, often grouped in fours and sometimes hidden behind a reveal control.
Best practices for handling TOTP secrets
- 1.Store enrollment secrets in the same secrets manager you already trust for API keys, encrypted at rest, with access logged, so break-glass recovery does not depend on a single phone.
- 2.Prefer SHA256 or SHA512 when the identity provider exposes the choice, and record the algorithm next to the secret; half of all failed migrations come from an unstated SHA1 default.
- 3.Give automated test fixtures a fixed timestamp rather than reading the wall clock, which turns flaky time-dependent assertions into deterministic ones.
- 4.Pair TOTP with single-sign-on or hardware keys for privileged accounts; time-based codes phish as easily as passwords when a fake login page relays them in real time.
Frequently asked questions
What is a TOTP code and how is it generated?
TOTP stands for time-based one-time password, the scheme behind Google Authenticator, Authy, 1Password, and most two-factor login prompts. The generator takes a shared Base32 secret, divides the current Unix time into fixed steps (usually 30 seconds), feeds that step counter into HMAC-SHA1, and truncates the digest down to a short numeric code, typically six or eight digits. Because both the server and your phone run the same math on the same clock step, they produce the same code without ever exchanging it over the network.
Is this TOTP generator safe to use with real accounts?
The code math runs locally in your browser tab with the Web Crypto API; the secret you paste is never transmitted anywhere because this page has no backend. That said, anyone who knows your Base32 secret can generate the same codes forever, so treat the secret with the same care as a password. Use this tool for reading codes when your phone is unavailable, testing your own two-factor implementations, and migrating secrets between authenticator apps, and avoid pasting secrets on shared or work-spied-on machines.
Why does my code stop working after 30 seconds?
That is the algorithm working as designed. Each code is valid only for the current time step plus a small acceptance window (most servers accept the previous, current, and next step, so roughly 30 to 90 seconds of life). The countdown bar in the tool shows how many seconds remain in the current step. If you type a code that was generated in an earlier step and the server has moved on, the login fails and you simply wait for the next code.
What Base32 format does the secret need to be in?
Authenticator secrets are shared as Base32 text using the alphabet A through Z and 2 through 7, usually in groups of four characters separated by spaces. The generator accepts the secret with or without spaces and with or without trailing equals-sign padding, then normalizes it before use. If you paste a Base64 string or a raw hex key by mistake, the tool reports the invalid character instead of silently producing wrong codes.
What is the difference between SHA1, SHA256, and SHA512 modes?
The three options are the HMAC hash functions the RFC 6238 standard allows. Almost every consumer authenticator and identity provider still uses SHA1 because that is the default in the original Google Authenticator implementation, and it remains fully acceptable for TOTP because the secret is high entropy. SHA256 and SHA512 appear in some enterprise deployments and in newer libraries that expose the algorithm parameter. Match whatever your provider configures; a mismatch produces codes that look valid but never authenticate.
How do I move an existing authenticator secret to this tool?
Most authenticator apps will not export the plain Base32 secret, which is deliberate. On Google Authenticator you can transfer via QR code export, and tools like a standard QR reader can surface the otpauth:// URI inside, which contains the secret parameter. Many enterprise single sign-on consoles and self-hosted two-factor servers (such as PrivacyIDEA or freeOTP setups) also display the raw secret when you enroll, and that text can be pasted straight into this generator.
Why does this generator show a countdown and step counter?
The step counter is the integer division of Unix epoch seconds by the period, and it is the actual input to the HMAC function. Showing it makes clock-drift debugging concrete: if your server rejects codes, comparing the counter your browser computes against the counter on the server (often logged during failed two-factor attempts) tells you immediately whether the clocks disagree or the secrets differ. The countdown simply maps the current step onto the seconds remaining before it rolls over.
Related security and token tools
Build signed test JSON Web Tokens entirely in the browser
Inspect header, claims, and expiry of any JSON Web Token
Create random keys and IVs for symmetric encryption
Hash strings with SHA-256, SHA-384, and SHA-512
Produce bcrypt password hashes with adjustable cost
Craft strong random passwords with entropy scoring