Versions in this module Expand all Collapse all v1 v1.1.0 Jul 10, 2026 Changes in this version + const DefaultChallengeMaxAttempts + const DefaultChallengeTTL + const DefaultOTPDigits + const DefaultTOTPDigits + const DefaultTOTPSecretLen + const DefaultTOTPSkew + const DefaultTOTPStep + func DecodeSecretBase32(s string) ([]byte, error) + func EncodeSecretBase32(secret []byte) (string, error) + func GenerateOTPCode(digits int) (string, error) + func GenerateTOTPSecret(n int) ([]byte, error) + func HOTPCode(key []byte, counter uint64, alg Algorithm, digits int) (string, error) + func HashOTPCode(salt, code string) string + func TOTPCodeAt(secret []byte, t time.Time, opts TOTPOptions) (string, error) + func VerifyOTPCode(salt, code, wantHash string) bool + func VerifyTOTPAt(secret []byte, code string, t time.Time, opts TOTPOptions) (bool, error) + type Algorithm string + const AlgSHA1 + const AlgSHA256 + const AlgSHA512 + type ChallengePolicy struct + MaxAttempts int + TTL time.Duration + func (p ChallengePolicy) AttemptsExhausted(st ChallengeState) bool + func (p ChallengePolicy) Evaluate(st ChallengeState, now time.Time) ChallengeStatus + func (p ChallengePolicy) Expired(st ChallengeState, now time.Time) bool + func (p ChallengePolicy) ExpiresAt(issuedAt time.Time) time.Time + func (p ChallengePolicy) MaxAttemptsOrDefault() int + func (p ChallengePolicy) TTLOrDefault() time.Duration + type ChallengeState struct + Attempts int + Consumed bool + IssuedAt time.Time + type ChallengeStatus int + const ChallengeAttemptsExhausted + const ChallengeConsumed + const ChallengeExpired + const ChallengeOK + func (s ChallengeStatus) OK() bool + func (s ChallengeStatus) String() string + type FakeSender struct + Deliveries []delivery + Err error + func (f *FakeSender) Count() int + func (f *FakeSender) LastCode() string + func (f *FakeSender) Reset() + func (f *FakeSender) Send(_ context.Context, destination, body string) error + type Sender interface + Send func(ctx context.Context, destination, body string) error + func NewLogSender(log *slog.Logger) Sender + type TOTPOptions struct + Algorithm Algorithm + Digits int + Skew int + Step time.Duration