captcha

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidToken     = errors.New("security captcha: invalid token")
	ErrProviderNotFound = errors.New("security captcha: provider not found")
)

Functions

This section is empty.

Types

type Base64Option

type Base64Option func(*base64Options)

func WithBase64DigitSize

func WithBase64DigitSize(height, width, length int) Base64Option

func WithBase64Driver

func WithBase64Driver(driver base64Captcha.Driver) Base64Option

func WithBase64Store

func WithBase64Store(store base64Captcha.Store) Base64Option

func WithBase64TTL

func WithBase64TTL(ttl time.Duration) Base64Option

type Base64Provider

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

func NewBase64Provider

func NewBase64Provider(opts ...Base64Option) *Base64Provider

func (*Base64Provider) Generate

func (p *Base64Provider) Generate(ctx context.Context, opts GenerateOptions) (*Challenge, error)

func (*Base64Provider) Kind

func (p *Base64Provider) Kind() Kind

func (*Base64Provider) Name

func (p *Base64Provider) Name() string

func (*Base64Provider) Verify

func (p *Base64Provider) Verify(ctx context.Context, id string, answer string) error

type Challenge

type Challenge struct {
	ID       string         `json:"id"`
	Kind     Kind           `json:"kind"`
	Image    string         `json:"image,omitempty"`
	Audio    string         `json:"audio,omitempty"`
	Payload  map[string]any `json:"payload,omitempty"`
	ExpireAt time.Time      `json:"expire_at,omitempty"`
}

type GenerateOptions

type GenerateOptions struct {
	TTL time.Duration
}

type Kind

type Kind string
const (
	KindImage  Kind = "image"
	KindSlider Kind = "slider"
)

type Manager

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

func NewManager

func NewManager(providers ...Provider) *Manager

func (*Manager) Generate

func (m *Manager) Generate(ctx context.Context, kind Kind, opts GenerateOptions) (*Challenge, error)

func (*Manager) ProviderName

func (m *Manager) ProviderName(kind Kind) string

func (*Manager) Register

func (m *Manager) Register(provider Provider)

func (*Manager) Verify

func (m *Manager) Verify(ctx context.Context, kind Kind, id string, answer string) error

type MemoryProvider

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

func NewMemoryProvider

func NewMemoryProvider(tokens ...string) *MemoryProvider

func (*MemoryProvider) Add

func (p *MemoryProvider) Add(token string)

func (*MemoryProvider) Generate

func (p *MemoryProvider) Generate(ctx context.Context, opts GenerateOptions) (*Challenge, error)

func (*MemoryProvider) Kind

func (p *MemoryProvider) Kind() Kind

func (*MemoryProvider) Name

func (p *MemoryProvider) Name() string

func (*MemoryProvider) Verify

func (p *MemoryProvider) Verify(ctx context.Context, id string, answer string) error

type NoopProvider

type NoopProvider struct{}

func (NoopProvider) Generate

func (NoopProvider) Generate(ctx context.Context, opts GenerateOptions) (*Challenge, error)

func (NoopProvider) Kind

func (NoopProvider) Kind() Kind

func (NoopProvider) Name

func (NoopProvider) Name() string

func (NoopProvider) Verify

func (NoopProvider) Verify(ctx context.Context, id string, answer string) error

type Provider

type Provider interface {
	Name() string
	Kind() Kind
	Generate(ctx context.Context, opts GenerateOptions) (*Challenge, error)
	Verify(ctx context.Context, id string, answer string) error
}

type StateStore

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

func NewStateStore

func NewStateStore(store state.Store, ttl time.Duration) *StateStore

func (*StateStore) Get

func (s *StateStore) Get(id string, clear bool) string

func (*StateStore) Set

func (s *StateStore) Set(id string, value string) error

func (*StateStore) Verify

func (s *StateStore) Verify(id string, answer string, clear bool) bool

Jump to

Keyboard shortcuts

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