Documentation
¶
Overview ¶
Package totp provides TOTP (Time-based One-Time Password) generation and validation. It wraps github.com/pquerna/otp for RFC 6238 compliant implementation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Generate ¶ added in v1.0.0
Generate creates a TOTP code for the given secret at the current time.
func Validate ¶ added in v1.0.0
Validate checks if the passcode is valid for the given secret. Uses a default time window of ±1 period (30 seconds).
func ValidateWithOpts ¶ added in v1.0.0
func ValidateWithOpts(passcode, secret string, opts ValidateOpts) (bool, error)
ValidateWithOpts checks if the passcode is valid with custom options.
Types ¶
type GenerateOpts ¶ added in v1.0.0
type GenerateOpts struct {
// Issuer is the name of the issuing organization (e.g., "MyApp").
Issuer string
// AccountName is the user's identifier (e.g., "user@example.com").
AccountName string
// SecretSize is the size of the secret in bytes. Default is 20.
SecretSize uint
// Algorithm is the hash algorithm. Default is SHA1.
Algorithm otp.Algorithm
// Digits is the number of digits in the OTP. Default is 6.
Digits otp.Digits
}
GenerateOpts configures the key generation.
type Key ¶ added in v1.0.0
Key represents a TOTP key with its configuration.
func GenerateSecret ¶ added in v1.0.0
func GenerateSecret(opts GenerateOpts) (*Key, error)
GenerateSecret creates a new TOTP secret key.
type ValidateOpts ¶ added in v1.0.0
type ValidateOpts struct {
// Skew is the number of periods before/after current time to check. Default is 1.
Skew uint
// Digits is the expected number of digits. Default is 6.
Digits otp.Digits
// Algorithm is the hash algorithm. Default is SHA1.
Algorithm otp.Algorithm
}
ValidateOpts configures the validation behavior.
Click to show internal directories.
Click to hide internal directories.