totp

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateTOTP

func GenerateTOTP(secret string, timestep int64) (string, error)

GenerateTOTP 生成基于时间的一次性密码(TOTP) secret: base32 编码的密钥字符串 timestep: 时间步长,单位秒,常用30秒 返回6位数字验证码,或错误

func GenerateTOTPWithTime

func GenerateTOTPWithTime(secret string, timestep int64, t time.Time) (string, error)

GenerateTOTPWithTime 生成指定时间点的 TOTP,功能同 GenerateTOTP,但支持自定义时间 secret: base32 编码密钥 timestep: 时间步长秒数 t: 指定时间点 返回6位验证码或错误

func ValidateTOTP

func ValidateTOTP(secret, code string, timestep int64) bool

ValidateTOTP 验证用户输入的验证码是否正确,允许当前时间步长前后各一个步长的误差 secret: base32 密钥 code: 用户输入的6位验证码 timestep: 时间步长,单位秒 返回是否验证通过

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL