Counter-Based OTP Generator Generate HMAC-based one-time passwords (HOTP) with counter tracking.
HOTP Generator
Generate HMAC-based one-time passwords (HOTP) with counter tracking.
Enter Secret
Base32 secret.
Set Counter
Counter value.
Generate OTP
Generate code.
What Is HOTP Generator?
A HOTP Generator is a software implementation of the HMAC-based One-Time Password algorithm defined in RFC 4226, which generates event-based one-time passwords using a shared secret and an incrementing counter. Developers implementing two-factor authentication systems use it to create secure login mechanisms for web applications, particularly those requiring offline access or hardware tokens. One specific problem this tool solves is generating dynamic HOTP codes that can be verified by the server without needing to store the actual password.
The key difference between other implementations and this one lies in its ability to auto-increment the counter after each code generation and track a history of previously generated codes, allowing for easier debugging and testing. For instance, it includes features like generating random Base32 secrets, configurable digit lengths, and client-side processing using the Web Crypto API.
It computes HMAC-SHA1 with dynamic truncation according to the HOTP specification, resulting in a secure 6 or 8-digit code that can be used as an HMAC OTP. Users of this tool can easily generate new codes by clicking the "Generate HOTP" button and then copy the result using the integrated copy-to-clipboard functionality, making it easier to work with the generated hotp code in other applications or systems.
Why Use HOTP Generator?
-
RFC 4226 compliant
-
Counter auto-increment
-
Generation history
-
100% client-side
Common Use Cases
Hardware Tokens
Test HOTP.
Development
Counter-based codes.
Offline Auth
No time sync.
Education
Counter vs time OTP.
Technical Guide
The tool works under the hood by first decoding a Base32 secret using the b32Dec function, which replaces whitespace and equals signs with an empty string, converts to uppercase, and then maps each character to its corresponding 5-bit value based on the Base32 alphabet defined in the constant A. This process results in a binary string that is then converted to a Uint8Array, which represents the decoded secret key.
The genHOTP function generates the HOTP code by creating an 8-byte big-endian counter using the DataView API and setting the counter value at offset 4. It then imports the decoded secret key as a raw key using the Web Crypto API's subtle.importKey method with the HMAC algorithm and SHA-1 hash, and signs the counter buffer using the subtle.sign method to produce an HMAC-SHA1 signature.
The tool applies dynamic truncation to the last byte of the signature by taking the offset from the last nibble, extracting 4 bytes starting at that offset, applying a mask to extract the lower 31 bits, and then reducing the result modulo 10 raised to the power of the desired number of digits. The counter is incremented after each successful code generation, ensuring that client and server stay in sync.
The b32Enc function is used to generate random Base32 secrets by creating a Uint8Array filled with random values using crypto.getRandomValues, converting each byte to its corresponding 5-bit value, padding to the nearest multiple of 5 bits if necessary, mapping these values back to characters based on the Base32 alphabet defined in A, and finally constructing the encoded string.
The Web Crypto API's subtle.importKey method allows importing the decoded secret key as a raw key for HMAC-SHA1 signing. In addition to generating HOTP codes, it also tracks code generation history by storing counter-code pairs in an array of objects when each new code is generated, allowing users to view previously generated codes and their corresponding counters.
The copyToClipboard function uses the navigator.clipboard API to copy the generated HOTP code directly into the user's system clipboard. The tool's UI components are built using React with hooks like useState for managing state changes, useCallback for memoizing functions that generate secrets or compute HOTP codes, ensuring efficient updates and minimizing unnecessary recalculations.
Each component is wrapped in a glass-card container to provide visual separation between sections of the interface, including input fields, buttons, history display.
Tips & Best Practices
-
1Generate a random secret by clicking the 'Random' button
-
2Set the counter to 0 when starting a new HOTP sequence
-
3Adjust the number of digits in the HOTP code using the digit buttons
-
4Copy the generated HOTP code to the clipboard by clicking the 'Copy' button
-
5View previous HOTP codes in the history section below the generator
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 Generator
Generate time-based one-time passwords (TOTP) compatible with Google Authenticator.
🔐 Encoding & Crypto
TOTP Validator
Validate TOTP codes against a shared secret with configurable time window.
🔐 Encoding & CryptoFrequently Asked Questions
Q Is the HOTP generator free?
Q What is the difference between HOTP and TOTP?
Q Is my secret key safe?
Q Do HOTP codes expire?
Q Does the counter auto-increment?
About This Tool
HOTP 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.