security

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountLockout

type AccountLockout struct {
	ID        string
	Email     string
	LockedAt  time.Time
	UnlocksAt time.Time
}

AccountLockout represents an account lockout due to too many failed attempts

type BruteForceAttempt

type BruteForceAttempt struct {
	ID        string
	Email     string
	IPAddress string
	Timestamp time.Time
}

BruteForceAttempt represents a failed login attempt

type BruteForceConfig

type BruteForceConfig struct {
	// Enabled enables brute force protection
	Enabled bool

	// MaxAttempts is the maximum number of failed login attempts before lockout
	MaxAttempts int

	// LockoutDuration is how long an account is locked after exceeding max attempts
	LockoutDuration time.Duration

	// AttemptWindow is the time window in which attempts are counted
	AttemptWindow time.Duration

	// MaxAttemptsPerIP is the maximum number of failed attempts from a single IP address
	// Set to 0 to disable IP-based rate limiting
	MaxAttemptsPerIP int

	// IPAttemptWindow is the time window for IP-based attempt counting
	IPAttemptWindow time.Duration

	// UseSecondaryStorage enables using secondary storage (e.g., Redis) instead of in-memory
	UseSecondaryStorage bool
}

BruteForceConfig contains configuration for brute force protection

func DefaultBruteForceConfig

func DefaultBruteForceConfig() *BruteForceConfig

DefaultBruteForceConfig returns the default brute force protection configuration

func (*BruteForceConfig) Validate

func (c *BruteForceConfig) Validate() error

Validate validates the brute force configuration

type BruteForceRepository

type BruteForceRepository interface {
	// RecordAttempt records a failed login attempt for an email/IP combination
	RecordAttempt(email, ipAddress string) error

	// GetAttemptCount returns the number of failed attempts in the last duration for an email
	GetAttemptCount(email string, duration time.Duration) (int, error)

	// GetAttemptCountByIP returns the number of failed attempts in the last duration for an IP
	GetAttemptCountByIP(ipAddress string, duration time.Duration) (int, error)

	// LockAccount locks an account until the specified time
	LockAccount(email string, unlocksAt time.Time) error

	// UnlockAccount unlocks a locked account
	UnlockAccount(email string) error

	// IsAccountLocked checks if an account is currently locked
	IsAccountLocked(email string) (bool, error)

	// GetLockoutInfo returns lockout information for an email
	GetLockoutInfo(email string) (*AccountLockout, error)

	// ClearAttempts clears all failed attempts for an email
	ClearAttempts(email string) error
}

BruteForceRepository defines the interface for managing brute force attempts

Jump to

Keyboard shortcuts

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