Online Tool Store Online Tool Store
🔒 Security & Privacy

· 3 min read

How to Generate and Test TOTP Codes

Manesh Jayawardhana

CIO & Co-founder

Manesh Jayawardhana is the CIO and Co-Founder of Ceyentra Technologies, where he has spent over nine years leading the design and delivery of software solutions for clients across the globe, spanning web, mobile, AI, and capital market systems. He has grown Online Tool Store's engineering team from the ground up while steering the company's technical direction. His writing draws on this breadth of experience building and shipping software across a wide range of industries and markets. View on LinkedIn

Share

How to Generate and Test TOTP Codes

Two-factor authentication codes look like six random digits, but they are generated from a shared secret and the current time. When a code fails, the cause might be the secret, the algorithm, the number of digits, the time period, or clock drift. Guessing at the problem is slow.

A TOTP code generator helps you generate, inspect, and verify time-based one-time passwords in the browser, with controls for algorithm, period, digits, and otpauth URI setup.

What TOTP generation involves

TOTP stands for time-based one-time password. It combines a secret key with a time counter, then calculates a short code using an HMAC algorithm. Most authenticator apps use 6 digits and a 30-second period, but other settings exist.

An otpauth:// URI packages the issuer, account, secret, algorithm, digits, and period so authenticator apps can import the setup.

Why people get stuck here

Most TOTP failures are configuration mismatches. The app and server must agree on the secret, algorithm, digit count, and time period. A small clock difference can also make a valid code appear expired or not yet active.

Testing with a clear verifier helps separate setup mistakes from time drift.

SettingCommon Default
Digits6
Period30 seconds
AlgorithmSHA-1 in many systems
SecretShared between verifier and app

What a good TOTP test looks like

Settings are explicit

Do not assume every system uses the same algorithm or digit count.

Clock drift is visible

The verifier should show whether a code is close but outside the expected time window.

URI contents are inspectable

An otpauth URI should be decoded so you can verify issuer, account, and parameters.

Common mistakes to avoid

  • Copying the wrong secret. One missing or extra character breaks codes.
  • Ignoring clock drift. Server and device time must be close.
  • Assuming SHA-1 always. Some systems use SHA-256 or SHA-512.
  • Sharing real 2FA secrets casually. Treat secrets like passwords.

How to do it with TOTP Code Generator

  1. Open the free TOTP Code Generator.
  2. Enter or generate a TOTP secret.
  3. Set the algorithm, digit count, and period.
  4. Generate the current code.
  5. Use the verifier to test a code and inspect clock-drift feedback.
  6. Create or inspect an otpauth:// URI when setting up an authenticator app.

This is useful for testing integrations and understanding why a one-time code is accepted or rejected.

Frequently asked questions

What is an otpauth URI?

It is a setup URL that authenticator apps use to import account name, issuer, secret, and TOTP settings.

Why did my valid-looking code fail?

The secret, algorithm, digit count, period, or clock may not match the verifier.

Are TOTP secrets sensitive?

Yes. Anyone with the secret can generate valid codes, so protect it carefully.

Final thought

TOTP is reliable when both sides agree on the same inputs and time. A generator makes those assumptions visible.

Try the free TOTP Code Generator

#totp-code-generator#time-based-one-time-password#totp-verifier#otpauth-uri-generator#online-tools#free-tools