Skip to main content

Generate Time-Based 2FA Codes Online Generate time-based one-time passwords (TOTP) compatible with Google Authenticator.

TOTP Generator illustration
🔐

TOTP Generator

Generate time-based one-time passwords (TOTP) compatible with Google Authenticator.

1

Enter Secret

Enter Base32 secret or generate random.

2

Configure

Set period and digits.

3

View Code

TOTP auto-refreshes each period.

Loading tool...

What Is TOTP Generator?

A TOTP Generator is a software tool that generates short-lived numeric codes based on a shared secret and the current time, following the guidelines set by RFC 6238. This type of generator is commonly used by developers and security professionals to implement two-factor authentication (2FA) in their applications, as it powers popular authenticator apps like Google Authenticator. One specific problem it solves is providing a secure way to generate Time-Based One-Time Passwords (TOTP), which are essential for 2FA systems.

The primary users of this tool are developers who need to integrate TOTP authentication into their web or mobile applications, and security professionals responsible for implementing robust authentication mechanisms. It helps solve the problem of generating authenticator codes that change every few seconds, making it difficult for attackers to guess or intercept them.

What makes this particular implementation different is its use of the Web Crypto API to compute HMAC-SHA1 over the time step counter, allowing for client-side generation of 6 or 8 digit TOTP codes with configurable periods. It also features a visual countdown and random secret generation, making it easier for users to manage their 2FA settings. The tool's ability to generate new secrets in Base32 format and its support for different period lengths set it apart from other TOTP generators, providing more flexibility for developers implementing 2FA systems that rely on time based OTP or authenticator codes generated by a 2fa generator like this one.

Why Use TOTP Generator?

  • RFC 6238 compliant
  • Random secret generation
  • 100% client-side

Common Use Cases

2FA Testing

Test 2FA implementations.

Development

Generate codes during dev.

Recovery

Verify secrets.

Education

Learn TOTP.

Technical Guide

The tool works by first decoding the Base32 secret using a custom `b32Dec` function that converts each character to its corresponding binary value based on the Base32 alphabet defined in the RFC 4648 standard. This decoded secret is then used as the key for computing the HMAC-SHA1 hash over an 8-byte big-endian buffer containing the time step counter, which is calculated by dividing the current Unix timestamp by the specified period and taking the floor of the result. The `crypto.subtle.importKey` function from the Web Crypto API is used to import the decoded secret as a raw key for use with the HMAC algorithm.

The tool then uses the `crypto.subtle.sign` function to compute the HMAC-SHA1 hash over the time step buffer, producing a signature that is subsequently truncated using dynamic truncation. This involves taking the last nibble of the signature to determine the offset into the signature where the 4-byte code will be extracted, masking the extracted bytes with `0x7FFFFFFF` to ensure they are unsigned, and then reducing the result modulo `10^digits` to produce a numeric code with the desired number of digits. The resulting Time-Based One-Time Password (TOTP) is displayed to the user along with a visual countdown indicating when it will expire.

The tool's use of React for building the user interface allows for efficient updates to the display as the time step counter changes, while the `useCallback` and `useEffect` hooks are used to manage the generation of new TOTP codes at regular intervals based on the specified period. The `copyToClipboard` function from the `@/lib/utils` module is also used to enable users to easily copy the generated TOTP code for use in other applications or systems that support time-based one-time passwords, such as Google Authenticator or other authenticator apps.

Tips & Best Practices

  • 1
    Set a secret to generate a time-based OTP
  • 2
    Use the Random button to create a new Base32 secret
  • 3
    Adjust the period in seconds to change the refresh rate
  • 4
    Click Copy to send the current TOTP code to your clipboard
  • 5
    Select 6 or 8 digits for the authenticator code length

Related Tools

Frequently Asked Questions

Q Is the TOTP generator free?
Yes. It is free to use.
Q Does it work with Google Authenticator?
Yes. It uses the same algorithm.
Q Is my secret safe?
Yes. All processing runs in your browser; nothing is uploaded.
Q What is the default period?
30 seconds.
Q Can I use 8-digit codes?
Yes. You can choose 6 or 8 digits.

About This Tool

TOTP Generator 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.