TOTP Authenticator

Securely generate and verify TOTP codes for 2FA. Support for SHA-1, SHA-256, and SHA-512 with built-in clock drift diagnostics. Keep your accounts private.

xDevToolsInitializing Tool

Related Utilities

Last Updated: August 14, 2026|Author: Yogeesh S, Senior Software Engineer

How the TOTP Algorithm Synchronizes Security Tokens

The TOTP (Time-Based One-Time Password) process relies on a shared secret and the current Unix timestamp to generate a synchronized code. At its core, the system calculates a hash based on the current time window, effectively creating a moving target for authentication.

The formula for the TOTP value is defined as:

$$ TOTP = Truncate(HMAC(K, T)) $$

Where $K$ is the secret key in bytes and $T$ is the number of time steps elapsed since the Unix epoch. The $Truncate$ function extracts a specific sequence of digits from the HMAC result to provide the final 6 or 8-digit code. By adjusting the time step, typically set to 30 seconds, you balance security against the likelihood of clock drift.

Comparing TOTP Algorithm Variants and Security Profiles

Selecting the right hashing algorithm is critical for ensuring compatibility with your existing 2FA systems. While SHA-1 remains the industry standard for most legacy applications, current implementations often prefer stronger hashing functions to improve collision resistance.

AlgorithmSecurity ProfilePrimary Use Case
SHA-1BaselineStandard legacy and web-based 2FA support
SHA-256HighEnhanced security for sensitive enterprise tokens
SHA-512MaximumAdvanced cryptographic requirements and compliance

Customizing Your TOTP Authenticator Settings

You can modify several variables to test how your time-based one-time password generator behaves under different requirements. The "Authenticator Secret" field accepts a Base32 string, which serves as the root of your unique token generation.

  • Digits: Toggle between 6-digit or 8-digit outputs. Most standard 2FA apps default to 6, but high-security environments sometimes use 8 for increased entropy.
  • Algorithm: Choose between SHA-1, SHA-256, or SHA-512. Ensure this matches the expected configuration of the service you are protecting.
  • Time Step: Adjust the window for token validity. While 30s is the global standard, you can shorten it to 15s for tighter windows or extend it to 60s to accommodate slow manual entry.

Verifying TOTP Codes and Diagnosing Clock Drift

When your 2FA system rejects a code, the culprit is often "clock drift"—a discrepancy between your local system time and the server time. This tool includes a built-in verifier that checks the current token against a range of offsets.

1

Input your Base32 secret

Paste your shared key into the Authenticator Secret field to initialize the generator.

2

Enter the token

Type the current 6-digit code provided by your app into the "Token Verifier" input.

3

Analyze drift

Click "Verify OTP" to see if the tool detects a clock mismatch.

4

Review diagnostic logs

If the match is successful but not at "Perfect sync," the tool calculates the exact offset (e.g., "30s behind") to help you calibrate your device.

Example Workflow: Troubleshooting a Failed 2FA Login

If you are locked out of an account, you can simulate the validation process to identify if your device clock is lagging. Suppose you have a secret key of JBSWY3DPEHPK3PXP and the server expects a 6-digit code.

BEFORE (INPUT)
Secret: JBSWY3DPEHPK3PXP
Token Input: 284910
AFTER (OUTPUT)
Drift Status: Detected
Message: "Drift detected: Your device is 30s behind the client time step."

Generating Backup Recovery Codes for Account Access

If you ever lose access to your authenticator app, backup codes are your last line of defense. The generator creates 8 distinct, high-entropy codes designed to be printed or stored in a secure physical location.

You should always generate these codes immediately upon setting up a new secret. Treat these as you would a physical key; if an attacker gains access to your backup list, they can work around your 2FA protections entirely.

Advanced Usage of the TOTP Token Generator

For developers, the "Show App Setup QR" feature is necessary for testing enrollment flows. It generates an otpauth:// URI that can be scanned by standard mobile authenticator apps.

If you are building an authentication service, this URI acts as the contract between your server and the user's mobile device. Testing different time steps and algorithms here ensures that your backend logic correctly handles edge cases, such as rapid token generation or high-latency network requests during the verification handshake.

Resolving TOTP Verification and Clock Drift Conflicts

Why does my TOTP code change every 30 seconds?

The time-based one-time password algorithm uses the current Unix epoch divided by the time step. As the current second value increments, the input to the hash function changes, resulting in a new output.

When should I choose SHA-512 over SHA-1 for 2FA?

You should choose SHA-512 when your organizational compliance requirements demand stronger cryptographic primitives. Note that not all legacy mobile apps support algorithms beyond SHA-1.

What does the "Drift detected" message mean during verification?

It means your device's internal clock is not perfectly synchronized with the server's time. The verifier checks ±5 time steps to confirm the code matches a valid window, allowing you to identify if you are ahead or behind.

Can I use an 8-digit code for all services?

No, most services strictly enforce a 6-digit requirement for 2FA compatibility. Only use 8 digits if the specific service documentation explicitly requires or permits it.

Where should I store my generated backup codes?

You should store them in a secure password manager or a printed physical document. Never store them in plain text on your desktop or in cloud-synced notes.

How do I fix a consistent "OTP verification failed" error?

First, ensure your device time is set to "Automatic" in your OS settings. If the error persists, use the totp verifier tool to check if your clock is drifting by more than the allowed 5-step window.

Does the Base32 secret need to be kept private?

Yes, the secret is the master key for your totp generator. Anyone with this string can generate valid codes for your account, effectively bypassing your second factor.

Which time step is most secure?

A shorter time step, such as 15 seconds, reduces the window of opportunity for an attacker to use a intercepted code. However, it also increases the risk of authentication failures due to minor network latency or clock jitter.