Skip to main content

Generate the Next Counter-Based One-Time Password (utils.hotp_next)

Declaration​

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

Parameters​

  • url
    String. HOTP URL in the otpauth://hotp/... 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 the next one-time password from an HOTP URL.
Use utils.hotp_counter if you need to specify the counter yourself.
The URL usually contains secret, and may also contain digits and algorithm.
algorithm can be SHA1, SHA256, or SHA512.

Examples​

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

local code, err = utils.hotp_next(url)
if code then
nLog(code)
else
nLog(err)
end