Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalid is returned when an invalid TOTP code is validated. ErrInvalid = errors.New("invalid") // ErrUsed is returned when a valid TOTP is validated second time. ErrUsed = errors.New("used") )
Functions ¶
func Generate ¶
Generate returns a 6 digit representation of the TOTP code using 30 seconds time interval. Secret must be in raw format (i.e. not base32 encoded).
func URI ¶
URI returns TOTP representation as URI. https://github.com/google/google-authenticator/wiki/Key-Uri-Format
func Validate ¶
Validate returns no error if given code is currently a valid TOTP code for given secret. Each code must be used only once - cache is used to mark code as used and prevent further validation.
A code is valid for 1 minute, meaning the current time span and the previous one are both accepted.
func WithCurrentTime ¶
WithCurrentTime is changing this package time perception to a fixed value. Calling this function alters this package "now" time until the end of the test. This function is not safe for concurent use as it is affecting package's global state.
Types ¶
This section is empty.