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 theotpauth://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 containssecret, and may also containdigitsandalgorithm.
algorithmcan beSHA1,SHA256, orSHA512.
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