Skip to main content

TOTP Validator Validate TOTP codes against a shared secret with configurable time window.

TOTP Validator illustration
🔐

TOTP Validator

Validate TOTP codes against a shared secret with configurable time window.

1

Enter Secret

Base32 secret.

2

Enter Code

TOTP code.

3

Validate

Check code.

Loading tool...

What Is TOTP Validator?

A TOTP Validator is a tool that checks the validity of Time-Based One-Time Password (TOTP) codes against a shared secret key. It's commonly used by developers and security professionals to test and debug two-factor authentication (2FA) systems, particularly when implementing verify TOTP or validate OTP mechanisms. One specific problem it solves is handling clock skew between the client and server, which can cause valid codes to be rejected due to slight time discrepancies.

This issue is addressed by checking not only the current time window but also adjacent windows for a specified tolerance period, allowing for some flexibility in case of minor clock deviations. What makes this tool different is its ability to generate TOTP codes using HMAC-SHA1 via the Web Crypto API and then compare them with user-inputted codes, reporting whether they match and if so, what the time offset is.

The tool also provides features like adjustable period and digits settings, allowing users to customize the validation process according to their specific needs, such as when working with 2FA validator or trying to figure out how to verify TOTP codes. With all processing happening client-side, it ensures that sensitive information like the shared secret remains secure, making it a reliable choice for validating 2FA codes online and serving as a useful TOTP checker in various authentication testing scenarios.

Why Use TOTP Validator?

  • Configurable time window
  • Reports time offset
  • Standard parameters
  • 100% client-side

Common Use Cases

2FA Testing

Test implementations.

Troubleshooting

Debug rejected codes.

Migration

Verify secrets.

Audit

Test config.

Technical Guide

The tool works by generating expected Time-Based One-Time Password (TOTP) codes for a given time period using the HMAC-based One-time Password algorithm as defined in RFC 4226. It utilizes the Web Crypto API to compute the HMAC-SHA1 of a counter value, which is derived from the current time and a specified period. The secret key used for this computation is first decoded from Base32 format to a binary array using a custom function b32Dec, which replaces whitespace and equals signs with nothing, then converts each character to its corresponding 5-bit index in the Base32 alphabet.

This binary array is then imported into the Web Crypto API as a raw key, which is used for signing the counter value. The resulting signature is truncated according to the dynamic truncation method specified in RFC 4226, and the least significant 4 bytes of this truncated value are extracted and converted to an integer. This integer is then reduced modulo 10 raised to the power of the number of digits, which results in the final TOTP code.

The tool checks for validity by generating codes for time steps from T-window to T+window, where window is a user-specified tolerance period, allowing it to account for clock skew between the client and server. For example, with a window of 1, it generates codes for three time steps: T-1, T, and T+1, corresponding to 30 seconds before, at, and after the current time step.

The genTOTP function implements this logic using React state management to store user input such as secret key, period, digits, and window size. When the validate button is clicked, it calls the validate function which iterates over each possible offset in the specified window, generates a TOTP code for that offset, and checks if it matches the provided code.

In terms of data structures, the tool uses Uint8Array to represent binary arrays such as secret keys and signatures. It also utilizes React state management to store user input in JavaScript objects, which are then used to generate TOTP codes and perform validation.

The use of specific technologies like React for building the user interface, Web Crypto API for cryptographic operations, and TypeScript for static type checking ensures that the tool is both secure and maintainable. Additionally, adherence to standards such as RFC 4226 guarantees interoperability with other systems implementing Time-Based One-Time Passwords.

This approach enables developers and security professionals to easily test and debug two-factor authentication systems without compromising sensitive information like shared secret keys. The client-side processing ensures that the validation process remains secure even when used over an insecure network connection.

The dynamic truncation method specified in RFC 4226 allows for flexible code generation, making it suitable for various applications where Time-Based One-Time Passwords are required. By using established algorithms and technologies, this tool simplifies the development of two-factor authentication systems while maintaining a high level of security.

Tips & Best Practices

  • 1
    Use Base32 secrets only, as attempted use of other formats will throw an error
  • 2
    Set the period to match your TOTP generator's setting, typically 30 seconds
  • 3
    Adjust the window size to account for potential clock skew between devices
  • 4
    Enter codes exactly as generated, with no extra spaces or characters
  • 5
    Verify that digits and period settings are correctly configured before validating a code

Related Tools

Frequently Asked Questions

Q Is the TOTP validator free?
Yes.
Q What does the window parameter do?
Checks adjacent periods.
Q Is my secret safe?
Yes.
Q What does a non-zero offset mean?
Clock drift, still valid.
Q Can I use a custom period?
Yes.

About This Tool

TOTP Validator is a free online tool by FreeToolkit.ai. All processing happens directly in your browser — your data never leaves your device. No registration or installation required.