HOTP Generator
Counter-based one-time passwords (RFC 4226). Enter the secret and counter to reproduce an HOTP code in the browser.
- Secret never leaves your browser
- Nothing you paste is uploaded
- Works instantly, no signup
Last updated: Oct 15, 2026 09:55:14
Generate a one-time code
Computed in your browser: the secret is not uploaded and not stored. The page makes one analytics request and nothing else.
HOTP is the older of the two one-time-password schemes (RFC 4226), and it is still in circulation: hardware tokens, some VPN concentrators, a few banking systems and printed scratch lists. The difference from TOTP is a single input — a counter that goes up by one on every use instead of a clock that ticks.
That one change has consequences: nothing expires, nothing drifts, and a lost code can silently desynchronise the device from the server.
How HOTP works
Nearly identical to TOTP, with the time replaced:
- The device and the server each hold the same secret and the same counter value.
- HMAC is computed over the counter (eight bytes, big-endian) keyed with the secret.
- The digest is truncated to a 31-bit integer and reduced modulo 10digits.
- On success, both sides increment the counter by one.
Use the counter field above to reproduce a specific value. The default of 0 is the first code a device would produce; 1 is the second, and so on.
Where you still meet HOTP
| Context | Why HOTP rather than TOTP |
|---|---|
| Hardware tokens | No clock to drift and no battery to run one; a button press advances the counter |
| Some VPNs and legacy SSO | Deployed before TOTP was common, and never migrated |
| Printed scratch lists | Each printed line is the next counter value — a paper HOTP chain |
| Transactional signing | The counter can be bound to a transaction sequence rather than a moment |
Consumer authenticator apps generally support HOTP entries, because the enrolment link carries type=hotp and a counter= parameter. If an app only ever shows countdown rings, it may still add HOTP entries silently — the ring is simply meaningless for them.
Desynchronisation, the characteristic failure
With TOTP, a bad code costs you 30 seconds. With HOTP, a bad code costs you a counter value, and the device and server can drift apart permanently.
The usual sequence: the user presses the button but the login fails (network, wrong password), the device increments, the server does not. Now every subsequent code is one step ahead of what the server expects.
Servers handle this with a look-ahead window: they accept the next few counter values, commonly ten, and resynchronise on a match. That is why a token that “stopped working” often recovers after a few attempts — and why a large window is a security trade-off, since it also widens the set of acceptable codes.
If your token fails once and then works, you were resynchronised. If it fails permanently after repeated wrong presses, the window has been exhausted and an administrator has to reset the counter.
Reading a counter-based token
If you are holding a hardware token with a button and a small screen, the workflow is not “look at the display” — it is a small protocol:
- Start typing your password first, so the token code is used within seconds of being generated.
- Press the button once. The value shown is the code for the current counter.
- Type it and submit immediately. A second press advances the counter and invalidates what you just read.
- If the login fails after a correct code, do not press repeatedly — each press can push the token further ahead of the server.
That last point is the counter-intuitive one: with TOTP, retrying is harmless; with HOTP, retrying is what turns a transient failure into a resynchronisation ticket.
Four mistakes when implementing HOTP
- Storing the counter insecurely. If an attacker can roll the counter back, previously used codes become valid again.
- Incrementing on failure. A server that advances its counter before verifying will desynchronise the client on every failed attempt.
- A too-large look-ahead window. Accepting the next hundred values defeats the single-use property.
- Comparing with
===. Constant-time comparison matters for anything derived from a secret; a naive string compare leaks timing.
Security notes that matter more here
- The counter must never repeat. Reusing a counter value with the same secret reproduces a code that the server may still accept — the whole reason HOTP is single-use.
- Codes do not expire. An HOTP code remains valid until the counter advances, which means an intercepted code can be replayed later if the legitimate user never completes a login.
- The secret is still the crown jewel. Same as TOTP: possession of the secret means unlimited future codes, without any device.
- Window size is a policy decision. Larger resynchronisation windows are more forgiving and slightly weaker.
Where the counter value comes from
If you are trying to reproduce a code from a device, the counter is the only unknown. Three ways to find it:
- Ask the issuer. Enterprise deployments usually record the last accepted counter and can tell you what value comes next.
- Count backwards from a known event. If the token was issued but never used, the counter is 0 or 1 depending on whether provisioned activations count.
- Try a small range. Servers accept the next few values to resynchronise, so a handful of guesses from the last known good counter will usually land.
A counter that is guessable within a few values is normal for HOTP — it is a sequence, not a secret. What must stay secret is the key.
Choosing between them
For anything new, TOTP wins: no state to desynchronise, no support burden, no replay window that outlives the login. HOTP survives where a clock is impractical — a token with a ten-year battery and no display — or where an existing deployment makes migration expensive.
For the time-based variant, see what is TOTP and the TOTP generator. For the general case, the OTP generator handles both mechanisms from one field.
Frequently asked questions
What is the difference between HOTP and TOTP?
HOTP derives the code from a counter that increments on each use; TOTP derives it from the current time. TOTP never desynchronises, HOTP never expires.
Which counter value should I use?
The one the server currently expects. If the token was never used, start at 0. If it has been used, ask the issuer or try a small range, since servers accept the next few values to resynchronise.
Why does my hardware token keep failing?
Pressing the button advances the counter even when a login fails. After a few misses the token is ahead of the server and needs a counter reset.
Do HOTP codes expire?
No. A code stays valid until the counter advances, which is why an intercepted code can be replayed if the legitimate login never completes.
Can a TOTP app handle an HOTP account?
Yes if the enrolment link is otpauth://hotp/ with a counter parameter. Some apps hide the counter field, which makes resynchronisation difficult.
Is HOTP less secure than TOTP?
It has a different weakness: replay risk and counter desynchronisation. TOTP's weakness is clock dependence. Neither is a reason to prefer one strongly for new deployments - use TOTP.