HMAC-based One-Time Password (HOTP) is a type of one-time password (OTP) algorithm that is used for authenticating users in a variety of security applications. HOTP generates a unique numeric or alphanumeric code that is single-use and used for login or transaction validation.

The HOTP algorithm uses a combination of a shared secret key and a counter to generate the OTP. The counter increases each time a password is generated, ensuring that each OTP is unique. The secret key and the counter value are then processed using HMAC (Hash-based Message Authentication Code) cryptographic functions to generate a unique HOTP value.

HOTPs are event-driven, meaning a new OTP is only generated when a specific event happens (e.g., a user pressing a button on a hardware token or initiating a new login attempt). These passwords are not time-limited, meaning they will remain valid until the next event occurs and a new OTP is generated.

The use of a counter as a moving factor in the generation of the OTP is what separates HOTP from other OTP methods such as TOTP (Time-Based One-Time Password), which uses time as the moving factor.

How does HOTP work?

Hash-based One-Time Password (HOTP) works through a combination of a server-side “counter” and a secret key to create unique one-time passwords.

Here is a simplified step-by-step process of how it works.

Initialization

Initially, the server and the HOTP device (this could be a hardware token or a digital app) both agree on a secret key and a counter, starting from zero. The secret key is randomly generated and securely shared between the server and the HOTP device. 

Generation

Each time an OTP is needed, the HOTP device generates it based on the current counter value and the secret key. It combines the secret key and the counter value and passes them through a cryptographic algorithm (typically HMAC-SHA1). This generates a unique hash.

Truncation

The hash is then truncated into a more user-friendly format, often a 6-8 digit number. This number serves as the one-time password.

Increment

Once the OTP is used, the counter is incremented by one both server-side and on the HOTP device, preparing for the next OTP generation. This is the event that leads to a new OTP in HOTP.

Authentication

When the user inputs the OTP into the system, the server validates it. The server generates an OTP using its stored secret key and the counter and checks if it matches the OTP provided by the user. If it matches, the user is granted access.

Synchronization

In case the counters on the server and the device go out of sync (typically due to unused OTP generations), the server may validate OTPs within a certain look-ahead window to re-sync and resolve the discrepancy.

Repeat

The process is repeated each time a user needs to authenticate, with each OTP generated being unique and valid only once.

It’s important to note that since HOTP is not time-bound, unused OTPs remain valid until the counter is incremented by a successful login or similar event. This differentiates it from other OTP mechanisms like TOTP, which are time-dependent.

What are the strengths of HOTP?

HOTP (Hash-Based One-Time Password) has several strengths that make it a popular choice for enhancing security across various digital platforms.

  • Uniqueness: Since a new password is generated for every login or transaction, it greatly reduces the risk of stolen or compromised passwords.
  • Independence from Time: Unlike TOTP (Time-based One-Time Password), HOTP does not rely on time synchronization between server and client. This can be an advantage in systems where time synchronization might be an issue.
  • Versatility: HOTP can be used in various authentication scenarios and is suitable for access control for digital and physical resources.
  • Robustness: HOTP is relatively simple to implement and maintain, making it a convenient solution for developers and security administrators.
  • Standardized: As described in RFC 4226, it allows interoperability between software and hardware from different vendors, making it an industry-wide, accepted form of two-factor authentication.
  • Resistant to Various Threats: It’s resistant to several types of attacks, such as replay attacks, where an attacker tries to use the same password to gain unauthorized access.
  • Adaptability: If network connectivity is an issue, a series of HOTPs can be generated in advance for use, something not possible with TOTP due to its reliance on time synchronization. 

What are the weaknesses of HOTP?

While HMAC-based One-Time Password (HOTP) is a secure method of authentication, it does have some limitations or weaknesses.

  • Counter Synchronization: If the counter on the server and the client become out-of-sync (possibly due to generating but not using OTPs), the authentication will fail, creating inconvenience and requiring additional steps to reset or resync the counters.
  • Phishing Risk: Just like any other credential, HOTPs can be captured via phishing attacks. If an attacker can trick a user into entering their OTP, the attacker can use it instead.
  • Man-in-the-Middle Attacks: Similar to the phishing risk, if an attacker can intercept the communication between the client and the server, they can capture the OTP and gain unauthorized access.
  • Dependence on Device: If the device used for generating the OTP is lost, stolen or malfunctions, the user cannot authenticate until a new device is associated with their account.
  • No Local Confirmation: Unless implemented as a challenge-response, the user does not receive a local confirmation that the OTP has actually been used.
  • Vulnerability to Brute-Force Attacks: If the server doesn’t implement a limit on failed attempts, an attacker could potentially try all possible OTPs to gain access.
  • OTP Sharing: If the client and server have not shared the starting counter value and secret key securely, it can leave vulnerabilities that can be exploited by attackers.

What’s the difference between OTP, HOTP, and TOTP?

OTP, HOTP, and TOTP are all related methods of authentication, but they each work a little differently.

One-Time Password (OTP)

This is a password that is valid for only one login session or transaction. OTPs avoid the risk of password reuse because they aren’t usable after their intended use. OTP is the foundation for HOTP and TOTP.

HMAC-Based One-Time Password (HOTP)

This is a type of one-time password that is algorithmically generated with a shared secret key and an incrementing counter. The counter is increased each time an OTP is generated and both the server and the authentication device maintain the counter. HOTPs can be valid for an extended period and only expire when used or when the next OTP is generated. 

Time-Based One-Time Password (TOTP)

TOTP is a variation of the HOTP system. Instead of increasing a counter when the password is produced, TOTP generates a password based on the current time. TOTP passwords are only valid for a short period (usually 30-60 seconds), and a new one is generated when the validity period expires. This time-based nature of TOTP provides an additional layer of security compared to HOTP.

In summary, an OTP is valid for a single use, an HOTP is an event-based OTP driven by a counter, and a TOTP is an OTP that expires after a certain period, determined by the current time.

Ready to go Passwordless?

Indisputable identity-proofing, advanced biometrics-powered passwordless authentication and fraud detection in a single application.