HOTP: HMAC based One Time Password (HOTP)

HOTPR Documentation

HMAC based One Time Password (HOTP)

Description

An R6 class that implements the HMAC based One Time Password (HOTP) algorithm.

Initialization

HOTP$new(secret, digits = 6L, algorithm = "sha1")

Create an One Time Password object

  • secret a scalar character, the base32-based secret key.

  • digits an integer, the number of digits of the password.

  • algorithm the hash algorithm used, possible values are "sha1", "sha256" and "sha512".

Methods

HOTP$at(counter)

Generate an one time password at counter value.

  • counter a non-negative integer.

HOTP$verify(code, counter, ahead = 0L)

Verify if a given one time password is valid. Returns the matching counter value if there is a match within the ahead window. Otherwise return NULL.

  • code a string of digits.

  • counter a non-negative integer.

  • ahead a non-negative integer, the amount of counter ticks to look ahead.

HOTP$provisioning_uri(name, issuer = NULL, counter = 0L)

Return a provisioning uri which is compatible with google authenticator format.

  • name account name.

  • issuer issuer name.

  • counter a non-negative integer, initial counter.

See Also

https://datatracker.ietf.org/doc/html/rfc4226

Examples

p <- HOTP$new("JBSWY3DPEHPK3PXP")
p$at(8)

p$verify("964230", 8)
p$verify("964230", 7, ahead = 3)

p$provisioning_uri("Alice", issuer = "example.com", counter = 5)

randy3k/otp documentation built on Feb. 1, 2024, 9:39 a.m.