Generate Time-Based 2FA Codes Online Generate time-based one-time passwords (TOTP) compatible with Google Authenticator.
TOTP Generator
Generate time-based one-time passwords (TOTP) compatible with Google Authenticator.
Enter Secret
Enter Base32 secret or generate random.
Configure
Set period and digits.
View Code
TOTP auto-refreshes each period.
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
-
Visual countdown timer
-
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
-
1Set a secret to generate a time-based OTP
-
2Use the Random button to create a new Base32 secret
-
3Adjust the period in seconds to change the refresh rate
-
4Click Copy to send the current TOTP code to your clipboard
-
5Select 6 or 8 digits for the authenticator code length
Related Tools
Base32 Encode
Encode text to Base32 format using the RFC 4648 standard alphabet.
🔐 Encoding & Crypto
HMAC Generator
Generate HMAC digests with multiple hash algorithms.
🔐 Encoding & Crypto
TOTP Validator
Validate TOTP codes against a shared secret with configurable time window.
🔐 Encoding & Crypto
HOTP Generator
Generate HMAC-based one-time passwords (HOTP) with counter tracking.
🔐 Encoding & CryptoFrequently Asked Questions
Q Is the TOTP generator free?
Q Does it work with Google Authenticator?
Q Is my secret safe?
Q What is the default period?
Q Can I use 8-digit codes?
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.