totp

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateBackupCodes

func GenerateBackupCodes(n int) ([]string, error)

GenerateBackupCodes creates n random backup codes in "XXXX-XXXX" format.

func HashBackupCode

func HashBackupCode(code string) (string, error)

HashBackupCode returns a bcrypt hash of a backup code. The code is normalized to uppercase before hashing.

func ValidateCode

func ValidateCode(secret, code string) bool

ValidateCode checks whether a TOTP code is valid for the given secret. Uses a time window of ±1 period (30 seconds) for clock drift tolerance.

func VerifyBackupCode

func VerifyBackupCode(code, hash string) bool

VerifyBackupCode checks a plaintext code against a bcrypt hash. The code is normalized to uppercase before comparison.

Types

type Key

type Key struct {
	Secret string // Base32-encoded secret
	URL    string // otpauth:// provisioning URI for QR codes
}

Key wraps an OTP key with its secret and provisioning URI.

func GenerateKey

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

GenerateKey creates a new TOTP secret for the given issuer and account. The issuer appears in the authenticator app (e.g. "RapidGo"). The account identifies the user (typically their email).

Jump to

Keyboard shortcuts

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