DEVELOPER TOOL

TOTP Generator and Verifier

Get the current 2FA code from a base32 secret with a live countdown, verify a code, or create a new secret and enrollment QR code. It all runs on your device.

Current code
------
Verify a code
Create a new secret and enrollment QR code

About this TOTP generator

TOTP, the Time-based One-Time Password algorithm in RFC 6238, is what authenticator apps use for two-factor login codes. This tool computes the same codes from a base32 secret, shows how long the current code is valid, and lets you check a code you were given. It can also create a fresh secret together with an otpauth:// QR code for enrolling in an authenticator app. Everything runs on your device, using your device clock. No secret is sent anywhere or stored.

How a code is made

  1. The secret is decoded from base32 into bytes.
  2. The current Unix time is divided by the period, normally 30 seconds, to give a step counter.
  3. The counter is signed with HMAC (SHA-1 by default) using the secret as the key.
  4. A 4-byte slice of the result, chosen by its last digit, is converted to a number and cut down to 6 or 8 digits.

Two devices with the same secret and the same time make the same code, so no network is needed. The code changes at each period boundary.

Verify a code

The verifier checks a code against the previous, current and next time steps. Servers accept that small window because clocks drift and because typing a code takes a few seconds. The result tells you which step matched, so you can tell whether a clock is running early or late.

Making a new secret

The generator creates 20 random bytes (160 bits) and writes them in base32, which is the length most services use. The QR code holds an otpauth://totp/ link with the account name, issuer, secret, algorithm, digits and period. Authenticator apps such as Google Authenticator, Microsoft Authenticator, Authy, 1Password and Aegis can read it. Most apps ignore a non-default algorithm or period, so keep the defaults (SHA-1, 6 digits, 30 seconds) unless you control both sides.

Good to know

For random strings and passwords, use the password generator, and to read or build QR codes see the QR code generator.

Frequently asked questions

What is a TOTP code?

A TOTP code is a short number, usually six digits, calculated from a shared secret and the current time. It changes every 30 seconds and is used as a second step when signing in.

Is it safe to enter my 2FA secret here?

The calculation runs in your browser and the secret is not uploaded or saved. Still, avoid entering the secret for an important account on a computer you do not trust, because anyone who learns the secret can generate your codes.

Why does my code not match my authenticator app?

Check the secret, the digits, the period and the algorithm; all must match. Also check that this device's clock is correct, because the code depends on the time.

How does the verifier decide a code is valid?

It computes the codes for the previous, current and next time step and compares them with the one you typed. It shows which step matched, if any.

What do I do with the new secret and QR code?

Scan the QR code with an authenticator app, or type the secret into the app by hand. Then save the secret in a safe place and give the server the same value so it can verify codes.

Which authenticator apps work with the QR code?

Google Authenticator, Microsoft Authenticator, Authy, 1Password, Aegis and most other TOTP apps read the standard otpauth link. They normally use SHA-1, 6 digits and 30 seconds.