captcha

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMinuteLimit = 1
	DefaultDailyLimit  = 100
	DefaultStoreSize   = 100
)

Variables

This section is empty.

Functions

func RandomCode

func RandomCode(length int) string

Types

type Config

type Config struct {
	CodeLength    int                 `json:"code_length"`
	CodeExpiresIn int                 `json:"code_expires_in"`
	RateLimit     *VerificationConfig `json:"rate_limit"`
}

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(config *Config, sender Sender) *Manager

func (*Manager) Identifier

func (m *Manager) Identifier() string

func (*Manager) SendCode

func (m *Manager) SendCode(number string) error

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context) error

func (*Manager) Verify

func (m *Manager) Verify(number, code string) bool

type Sender

type Sender interface {
	SendCode(number string, code string) error
}

type VerificationCode

type VerificationCode struct {
	Code      string    `json:"code"`
	ExpiresAt time.Time `json:"expires_at"`
}

type VerificationConfig

type VerificationConfig struct {
	MinuteLimit int `json:"minute_limit"`
	DailyLimit  int `json:"daily_limit"`
}

type VerificationStorage

type VerificationStorage struct {
	Store map[string][]VerificationCode `json:"store"`

	MinuteCounts map[string]int `json:"minute_counts"`
	DailyCounts  map[string]int `json:"daily_counts"`

	MinuteTimestamps map[string]time.Time `json:"minute_timestamps"`
	DailyTimestamps  map[string]time.Time `json:"daily_timestamps"`
}

type VerificationSystem

type VerificationSystem struct {
	// contains filtered or unexported fields
}

func NewVerificationSystem

func NewVerificationSystem(config *VerificationConfig) *VerificationSystem

func (*VerificationSystem) CleanExpired

func (s *VerificationSystem) CleanExpired()

func (*VerificationSystem) GetCaptchaCount

func (s *VerificationSystem) GetCaptchaCount(number string) int

func (*VerificationSystem) SaveCode

func (s *VerificationSystem) SaveCode(number string, code string, expiresIn time.Duration) error

func (*VerificationSystem) Verify

func (s *VerificationSystem) Verify(number, code string) bool

Jump to

Keyboard shortcuts

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