Skip to content

TOTP code generator

Turn a two-factor secret into the current six-digit code, entirely in your browser.

Almost every service uses SHA-1 here, which is correct for TOTP and is not the same as using SHA-1 for a signature.
Runs in your browser — nothing is sent anywhere.

Read this first

A TOTP secret is the second factor. Not a copy of it, not something derived from it — it is the thing your authenticator app holds, and anyone with it can generate your codes indefinitely. If your password and this secret both live on the same laptop, you no longer have two factors; you have one factor written down twice.

This tool is genuinely safe from us — it runs in your browser and makes no network request, which you can confirm in the network tab. What it cannot protect you from is the habit. Use it to debug an integration, to recover access when a phone has died and you have the backup secret, or to check that a server's clock is the problem. Do not use it as your everyday authenticator.

How a six-digit code is derived from a secret

Worth understanding, because it explains every failure mode. The current Unix time is divided by the period — usually thirty seconds — to give a counter. That counter is HMAC'd with your secret. Four bytes are then picked out of the result at an offset determined by its own last nibble, the top bit is masked off, and the remainder modulo a million is the code.

Two consequences follow. Nothing is transmitted, so the code cannot be intercepted in transit — both sides compute it independently. And the whole scheme depends on both clocks agreeing: if a server's time is off by more than a minute, every code it generates is rejected, and "my authenticator stopped working" is very often a drifted clock rather than a wrong secret.

What you can paste in

Either the base32 secret from the setup screen — spaces, hyphens and lower case are all fine — or the whole otpauth:// URL from behind the QR code, in which case the account name, digit count, period and algorithm are read from it rather than guessed. If you have the QR code but not the text, the QR scanner will read it out for you without following it.

SHA-1 here is not a problem

Almost every service uses HMAC-SHA1 for TOTP and that is correct. SHA-1's weakness is collision resistance, which this construction does not rely on. Some services offer SHA-256 or SHA-512 and both are supported, but if a setup screen does not mention an algorithm it means SHA-1.

Verified against the specification's own test vectors

RFC 6238 publishes exact expected codes for a known secret at six specific instants, for all three hash algorithms. This implementation reproduces all eighteen of them, which is checked on every build. That is a stronger guarantee than "it seemed to work when I tried it", and for something that gates account access it seemed worth having.

01

Common questions

Is it safe to paste my 2FA secret here?

It is safe from us — nothing leaves your browser. But a secret stored anywhere other than your authenticator weakens the second factor, so use this for debugging and recovery, not day to day.

Why is my code being rejected?

Most often clock drift. Both sides derive the code from the current time, so a server more than about a minute out will reject every code. Check the clock before suspecting the secret.

What is the otpauth:// URL?

The text encoded in the QR code you scan during setup. It carries the secret plus the digits, period and algorithm, so pasting the whole thing is more reliable than the secret alone.

Why does everything use SHA-1?

Because TOTP does not depend on collision resistance, which is where SHA-1 is broken. HMAC-SHA1 remains sound here. SHA-256 and SHA-512 are supported if your service uses them.

Can I use this instead of an authenticator app?

You can, and you should not. The point of a second factor is that it lives somewhere separate from your password.

How is this verified?

Against the eighteen test vectors published in RFC 6238 itself, across SHA-1, SHA-256 and SHA-512, checked on every build.