Help us shape the future of Go! Take the 2026 Go Developer Survey

otpcode

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package otpcode is the TOTP arithmetic shared by every second step (a User's Second factor, ADR 0020, and a Staff member's TOTP, ADR 0026): new keys with their QR code, and matching a submitted code against a secret at a clock. It holds no state: each caller stores the last accepted time step itself and makes the conditional write that makes a code single-use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCode

func IsCode(s string) bool

IsCode reports whether s has the shape of a TOTP code (six digits).

func Match

func Match(secret, code string, now time.Time, lastStep int64) (step int64, ok bool, err error)

Match reports the time step code is the secret's code for, among the steps within the skew of now and later than lastStep (so a code of a step already accepted never matches). ok is false when no such step matches.

Types

type Key

type Key struct {
	Secret string // base32 key
	URI    string // otpauth:// URI
	QRCode string // PNG data URI of the URI
}

Key is a freshly generated TOTP secret, shown so it can be added to an app.

func FromSecret

func FromSecret(issuer, account, secret string) (*Key, error)

FromSecret rebuilds the Key of an existing base32 secret, so a pending enrolment can be shown again unchanged.

func New

func New(issuer, account string) (*Key, error)

New generates a key for account under issuer.

Jump to

Keyboard shortcuts

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