OTP code generator
Generate and validate time-based OTP (one time password) for multi-factor authentication.
About OTP code generator
Generates and checks time-based one-time passwords (TOTP, RFC 6238), the 6-digit codes that authenticator apps show for two-factor login. It shows the current code with the previous and next one, and gives you a key URI that can be turned into a QR code.
When you would use it
- Testing a two-factor login you are building, by comparing your server's code with a reference implementation.
- Generating a secret and a provisioning URI to add to an authenticator app during development.
- Working out why codes are rejected, for example because of clock drift between the server and the phone.
How to use it
- Use the generated secret or paste your own Base32 secret.
- Read the current 6-digit code; it changes every 30 seconds, and the previous and next codes are shown beside it.
- To enrol an app, use the key URI (otpauth://) or its QR code, then compare the app's code with the one shown here.
Things worth knowing
- The secret is Base32 (letters A to Z and digits 2 to 7). Characters outside that set, such as 0, 1, 8 and 9, are not valid in it.
- Codes use HMAC-SHA1, 6 digits and a 30-second step, the defaults of nearly all authenticator apps. Settings that differ, such as 8 digits or SHA-256, are not covered here.
- A code is derived from the current time, so the server and the device must have accurate clocks. Servers usually accept the previous and next code as well, which is why those are shown.
- Anyone who knows the secret can generate valid codes forever. Treat it as a password, and use test secrets only.
Frequently asked questions
- Why is my code different from my phone app?
- Either the secret differs, the app uses other settings (digits, algorithm or period), or a clock is off by more than about 30 seconds. Check the phone's time first, and make sure automatic time is on.
- What is the difference between TOTP and HOTP?
- HOTP uses a counter that increases with each use, while TOTP uses the current time divided into 30-second steps. TOTP is what authenticator apps use, and this tool is built around it.