Documentation
¶
Overview ¶
Package authenticator provides TOTP (Time-based One-Time Password) authentication implementation compatible with Google Authenticator, Microsoft Authenticator, and other standard TOTP applications.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateSecret ¶
GenerateSecret generates a new random secret key
Types ¶
type Authenticator ¶
type Authenticator struct {
// contains filtered or unexported fields
}
Authenticator handles TOTP generation and validation
func NewAuthenticator ¶
func NewAuthenticator(config Config) (*Authenticator, error)
NewAuthenticator creates a new Authenticator instance
func (*Authenticator) FormatSecretKey ¶
func (a *Authenticator) FormatSecretKey() string
FormatSecretKey formats the secret key for manual entry
func (*Authenticator) GenerateQRCode ¶
func (a *Authenticator) GenerateQRCode(accountName, issuer string) string
GenerateQRCode generates a QR code URI for the authenticator app
func (*Authenticator) GenerateTOTP ¶
func (a *Authenticator) GenerateTOTP() (string, error)
GenerateTOTP generates a TOTP token
func (*Authenticator) ValidateTOTP ¶
func (a *Authenticator) ValidateTOTP(token string, userId string) (bool, error)
ValidateTOTP validates a TOTP token
type Config ¶
type Config struct {
// Algorithm to use for TOTP generation
Algorithm Algorithm
// Digits is the length of the generated TOTP
Digits int
// Period is the time step in seconds
Period int
// Secret is the base32 encoded secret key
Secret string
}
Config holds the configuration for TOTP generation
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with standard settings
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter handles rate limiting for validation attempts
func (*RateLimiter) CheckLimit ¶
func (r *RateLimiter) CheckLimit(userId string) (bool, error)
CheckLimit checks if the rate limit has been exceeded