Documentation
¶
Overview ¶
Package security provides pure functions for security and lockout calculations.
Index ¶
- Constants
- func CalculateLockout(failedAttempts int64, now int64) sql.NullInt64
- func FormatLockoutDuration(lockedUntil int64, now int64) string
- func IncrementFailedAttempts(current int64) int64
- func IsLocked(lockedUntil sql.NullInt64, now int64) bool
- func ShouldClearLockout(lockedUntil sql.NullInt64, now int64) bool
- type UnlockAccountTask
Constants ¶
const LockoutDuration = 3600 // 1 hour
LockoutDuration is the duration of account lockout in seconds.
const LockoutThreshold = 3
LockoutThreshold is the number of failed attempts before account lockout.
Variables ¶
This section is empty.
Functions ¶
func CalculateLockout ¶
CalculateLockout calculates the lockout expiration timestamp based on failed attempts. Returns nil (invalid) if failed attempts < LockoutThreshold. Returns the expiration timestamp if failed attempts >= LockoutThreshold.
func FormatLockoutDuration ¶
FormatLockoutDuration converts the lockout duration to a human-readable string.
func IncrementFailedAttempts ¶
IncrementFailedAttempts increments the failed attempt counter.
Types ¶
type UnlockAccountTask ¶
type UnlockAccountTask struct {
Username string
UnlockFn func(ctx context.Context, username string) error
}
UnlockAccountTask unlocks a user account when the scheduled lockout period expires. It calls the database to clear failed attempts and reset the locked_until timestamp.