Web · real, tested code

Generate a One-Time Password (TOTP) in Larzscript

Generate and verify RFC 6238 time-based one-time codes - the same 6-digit codes an authenticator app shows.

totp.verify() checks a +/-1 time-step drift window, the same tolerance real authenticator flows need for clock skew.

larzscript pkg install totp

Code

import "totp" as totp

let secret = "JBSWY3DPEHPK3PXP"
let code = totp.generate(secret)
print(code)
print(totp.verify(secret, code))
Output
334803
true