Learn R Programming

otp (version 0.1.1)

TOTP: Time based One Time Password (TOTP)

Description

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

Arguments

Initialization


TOTP$new(secret, digits = 6L, period = 30, 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.

  • period a positive number, the number of seconds in a time step.

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

Methods


TOTP$at_time(t)

Generate an one time password at a given time value.

  • t a POSIXct object or an integer that represents the numbers of second since UNIX epoch.


HOTP$verify(code, t, behind = 0L)

Verify if a given one time password is valid. Returns the beginning time of the time step window if there is a match within the behind window. Otherwise return NULL.

  • code a string of digits.

  • t a POSIXct object or an integer that represents the number of seconds since UNIX epoch.

  • behind a non-negative integer, the amount of time steps to look behind. A value of 1 means to accept the code before period seconds ago.


HOTP$provisioning_uri(name, issuer = NULL)

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

  • name account name.

  • issuer issuer name.

See Also

Examples

Run this code
p <- TOTP$new("JBSWY3DPEHPK3PXP")
(code <- p$now())
p$verify(code, behind = 1)

(current_time <- Sys.time())
(code <- p$at_time(current_time))
p$verify(code, current_time + 30, behind = 1)

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

Run the code above in your browser using DataLab