Two-factor authentication adds a second proof of identity beyond your password, usually a short code that changes regularly and that only you can produce. The OTP Code Generator creates those codes in your browser from a secret key you already have, supporting both time-based codes that refresh every 30 seconds and counter-based codes that advance one step at a time. It implements the real standards behind authenticator apps, TOTP and HOTP, using HMAC-SHA1, so the codes it produces are the same codes an authenticator app would produce from the same secret. It also creates a fresh random secret when you need one, and it builds the setup link that an authenticator app uses to import an account. Your secret never leaves your browser, which is essential, because anyone who holds the secret can generate your codes.
What Is the OTP Code Generator?
The OTP Code Generator is a free browser-based tool that generates one-time passwords from a Base32 secret key. OTP stands for one-time password: a short numeric code that is valid for a single use or a short time window, and that cannot be reused after it expires. The tool supports two modes. TOTP, time-based one-time password, defined in RFC 6238, divides time into 30-second periods and generates a code from the current period number. The code changes every 30 seconds, and the tool refreshes it automatically once per second while a secret is entered, showing how many seconds remain before the next code. HOTP, HMAC-based one-time password, defined in RFC 4226, generates a code from a counter value that you advance manually. Each counter value produces a different code, and after using a code you move to the next counter value.
Both modes use HMAC-SHA1 to combine the secret with the time period or counter, then apply the standard dynamic truncation to produce a 6-digit or 8-digit code. The secret is entered as Base32 text, the encoding used by almost every two-factor setup screen, using only the letters A to Z and the digits 2 to 7. The tool validates the secret and reports invalid characters specifically, so a typo is easy to find. It strips spaces, hyphens, and padding characters before decoding, so secrets copied with formatting still work. The tool also offers a New Random Secret button, which generates 20 random bytes with the browser cryptographic random number generator and encodes them as Base32, giving you a fresh secret for testing or for setting up a new account where you control both sides.
For setup, the tool builds an otpauth link from the mode, secret, account name, issuer, digit count, and, for HOTP, the counter value. The Copy Setup Link button copies that link, which you can open in an authenticator app to import the account without typing the secret manually. The account and issuer fields are optional and exist only to make the setup link readable. The tool requires the Web Cryptography API over HTTPS in a modern browser, and it shows a notice if the API is unavailable.
How to Use the OTP Code Generator
- Choose the mode. Select TOTP for time-based codes, which is the mode almost every service uses, or HOTP for counter-based codes if your service or system specifically requires counter mode.
- Enter the Base32 secret. Paste the secret from your service two-factor setup screen into the Secret key field. The field notes that the secret never leaves your browser. The code updates automatically as you type a valid secret.
- Or generate a new random secret. Click New Random Secret to create a fresh 20-byte Base32 secret. Use this only when you are setting up a new account or testing, and you control the service side that must store the same secret. Do not replace a service secret with a new one unless the service lets you register it.
- Choose the code length. Select 6 digits, the standard length, or 8 digits if your service requires longer codes. The code updates when you change the length.
- For HOTP, set the counter. In HOTP mode, the Counter field appears. Enter the current counter value, starting from 0. After using a code, click Next Counter to advance by one and generate the next code. The counter field is hidden in TOTP mode.
- Read the code. The current code appears in a large display, with a hint showing the seconds remaining in TOTP mode or the counter value in HOTP mode. Use the Copy Code button to copy it without retyping.
- Optionally copy the setup link. Enter an account name and issuer if you want them in the link, then click Copy Setup Link. Open the copied otpauth link in an authenticator app to import the account.
Key Features of the OTP Code Generator
- Real TOTP and HOTP standards. Implements RFC 6238 and RFC 4226 with HMAC-SHA1, so codes match those produced by authenticator apps from the same secret, mode, and parameters.
- Automatic 30-second refresh for TOTP. The code updates every second while a secret is entered, with a countdown showing when the next code will appear, so you always use the current code.
- Manual counter control for HOTP. The counter field and Next Counter button let you step through codes in order, with the current counter value shown alongside the code.
- 6-digit and 8-digit codes. Choose the length your service expects, with automatic regeneration when the length changes.
- Base32 validation with specific errors. Invalid characters are named in the error message, and the allowed alphabet is explained, making it easy to fix a mistyped secret.
- Random secret generation. The New Random Secret button creates a fresh 20-byte secret encoded in Base32, using the browser cryptographic random number generator.
- Setup link generation. The otpauth link includes the mode, label, issuer, digit count, and period or counter, ready to open in an authenticator app.
- Complete secret privacy. The secret is used only in the browser and never transmitted. The tool warns that anyone with the secret can generate your codes, so it must be kept private.
Practical Use Cases With Concrete Examples
Accessing an account when your phone is unavailable. You have stored your two-factor secret securely, for example in a password manager, and your phone is lost or out of battery. Paste the secret here to generate the current TOTP code and sign in. This is a recovery path, not a daily habit: an authenticator app on a device you control is the normal way to generate codes.
Testing a two-factor implementation. A developer building sign-in with TOTP needs to verify that the server accepts correct codes and rejects wrong ones. Generate a secret here, register the same secret on the test server, and compare the code this tool produces with the code the server expects, including checking behavior at period boundaries.
Setting up an authenticator app without typing the secret. During setup, a service shows a secret that is long and easy to mistype. Paste it here, add the account name and issuer, copy the setup link, and open it in your authenticator app to import the account accurately.
Understanding how time-based codes work. Enter a test secret and watch the code change every 30 seconds, with the countdown showing the remaining time. The demonstration makes the concept of a moving time window concrete, and shows why a correct device clock matters.
Working with a counter-based hardware token system. A system that uses HOTP with a known counter can be tested by entering the secret and stepping the counter with the Next Counter button, verifying that each counter value produces the expected code in sequence.
Creating a secret for a self-hosted service. When you run your own service that supports TOTP, generate a random secret here, store it in the service configuration, and use the setup link to import it into your authenticator app, giving you second-factor protection for your own system.
Tips and Best Practices
- Keep the secret private. The secret is equivalent to the ability to generate your codes. Anyone who obtains it can bypass your second factor. Never share it, never paste it into untrusted sites, and never store it alongside the password it protects in an insecure place.
- Check your device clock if codes are rejected. TOTP codes depend on the current time. If codes are rejected, the tool hint reminds you to check that your device clock is correct, including the time zone and automatic time synchronization.
- Use the code promptly. In TOTP mode, a code is valid only for its 30-second window, and some services accept only the current window. If the countdown shows only a few seconds remaining, wait for the next code and use that one.
- Advance the HOTP counter after each use. Each counter value should be used once. After using a code, move to the next counter value with the Next Counter button, so the next code is fresh and the server counter stays in step.
- Store backup codes separately. Most services offer one-time backup codes for account recovery. Store those codes in a safe place separate from the secret, so you can recover access if the secret is lost.
- Prefer an authenticator app for daily use. This browser tool is useful for recovery, testing, and learning, but a dedicated authenticator app on a device you control is the more secure daily option, because the secret stays on that device and is not pasted into a web page.
- Protect the password too. Two-factor authentication strengthens a good password; it does not replace one. Use the Password Generator for strong unique passwords, and check them with the Password Strength Checker.
Limitations
The OTP Code Generator implements TOTP and HOTP with HMAC-SHA1 only. It does not support HMAC-SHA256 or HMAC-SHA512 variants, which some services use, and it uses a fixed 30-second period for TOTP, which is the standard but not universal. The tool cannot register a secret with a service, cannot recover a lost secret, and cannot generate codes without the correct secret. TOTP accuracy depends on the device clock: if the clock is wrong by more than the service tolerance, codes will be rejected even though they are correctly computed for the wrong time. Entering a real secret into any web page carries risk if the device or browser is compromised, so the tool should be used on a trusted device and, for daily use, replaced by a dedicated authenticator app. The setup link contains the secret in plain text, so anyone who obtains the copied link can import the account. The tool requires WebCrypto over HTTPS in a modern browser. Finally, the tool does not verify that a code will be accepted: acceptance depends on the service configuration, clock synchronization, and counter state, all of which are outside the tool control.
Frequently Asked Questions
What is the difference between TOTP and HOTP?
TOTP codes are based on the current time and change every 30 seconds. HOTP codes are based on a counter that advances by one for each code. Most consumer services use TOTP. HOTP is used by some hardware tokens and specialized systems that track a counter.
Where do I find my Base32 secret?
Your service shows it during two-factor setup, usually alongside a QR code, with an option to enter the key manually. That manually entered key is the Base32 secret. If you did not save it, you may need to disable and re-enable two-factor authentication to see a new secret.
Why is my TOTP code rejected?
The most common cause is a wrong device clock. Check that automatic time is enabled and the time zone is correct. Other causes include the wrong secret, the wrong digit length, or using a code from a previous time window after it expired.
Is it safe to paste my secret into this tool?
The secret never leaves your browser, so the tool itself does not transmit it. However, pasting a real secret into a web page should be done only on a device and browser you trust, and a dedicated authenticator app is safer for everyday use.
What does the setup link contain?
The otpauth link contains the mode, account label, issuer, secret, digit count, and period or counter. Opening it in an authenticator app imports the account. Because it contains the secret, treat the copied link as sensitive and do not share it.
Can the tool generate a secret for my existing account?
No. The New Random Secret button creates a new secret, which is useful only when you can register that secret with the service. For an existing account, you must use the secret the service issued, or re-enable two-factor authentication to get a new one from the service.
Related Tools
Related tools include the Password Generator for strong passwords, the Secret Key Generator for random keys, the PIN Code Generator for numeric codes, the Secure Token Generator for verification tokens, and the Password Breach Checker for checking credential exposure. Browse all tools from the homepage.