totp

package
v0.0.0-...-83cf971 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: LGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func Generate(now time.Time, secret []byte) string

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

func URI(issuer, account string, secret []byte) string

URI returns TOTP representation as URI. https://github.com/google/google-authenticator/wiki/Key-Uri-Format

func Validate

func Validate(ctx context.Context, c cache.Store, code string, secret secret.Value) error

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

func WithCurrentTime(t testing.TB, now time.Time)

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.

Jump to

Keyboard shortcuts

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