Skip to main content

Generate a One-Time Password by Counter (utils.hotp_counter)

Declaration​

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

Parameters​

  • counter
    Integer. Counter used to generate the HOTP code.
  • 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 a one-time password from the specified counter and HOTP URL.
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_counter(1, url)
if code then
nLog(code)
else
nLog(err)
end