Skip to main content

Generate a Time-Based One-Time Password (utils.totp_next)

Declaration

code, err = utils.totp_next(timestamp, url[, secret])

Parameters

  • timestamp
    Integer. Unix timestamp in seconds. Pass -1 to use the current time.
  • url
    String. TOTP URL in the otpauth://totp/... format.
  • secret
    String. Base32 secret. Optional. When provided, this secret is used to generate the code.

Returns

  • code
    String. Generated one-time password.
  • err
    String. Error message returned when generation fails.

Description

Available after 2026-01-07.
Generate a time-based one-time password from a TOTP URL.
The URL usually contains secret, and may also contain digits, period, and algorithm.
algorithm can be SHA1, SHA256, or SHA512.

Examples

local url = "otpauth://totp/Demo:alice?secret=JBSWY3DPEHPK3PXP&issuer=Demo&digits=6&period=30&algorithm=SHA1"

local code, err = utils.totp_next(-1, url)
if code then
nLog(code)
else
nLog(err)
end