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.

Examples

p <- HOTP$new("JBSWY3DPEHPK3PXP")
p$at(8)
#> [1] "964230"

p$verify("964230", 8)
#> [1] 8
p$verify("964230", 7, ahead = 3)
#> [1] 8

p$provisioning_uri("Alice", issuer = "example.com", counter = 5)
#> [1] "otpauth://hotp/example.com:Alice?secret=JBSWY3DPEHPK3PXP&issuer=example.com&counter=5"