security

package
v0.1.149 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package security provides pure functions for security and lockout calculations.

Index

Constants

View Source
const LockoutDuration = 3600 // 1 hour

LockoutDuration is the duration of account lockout in seconds.

View Source
const LockoutThreshold = 3

LockoutThreshold is the number of failed attempts before account lockout.

Variables

This section is empty.

Functions

func CalculateLockout

func CalculateLockout(failedAttempts int64, now int64) sql.NullInt64

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

func FormatLockoutDuration(lockedUntil int64, now int64) string

FormatLockoutDuration converts the lockout duration to a human-readable string.

func IncrementFailedAttempts

func IncrementFailedAttempts(current int64) int64

IncrementFailedAttempts increments the failed attempt counter.

func IsLocked

func IsLocked(lockedUntil sql.NullInt64, now int64) bool

IsLocked checks if an account is currently locked based on lockedUntil timestamp. Returns true if locked (lockedUntil is valid and in the future). Returns false if not locked or lockout has expired.

func ShouldClearLockout

func ShouldClearLockout(lockedUntil sql.NullInt64, now int64) bool

ShouldClearLockout determines if a lockout should be cleared based on expiration. Returns true if the lockout has expired (lockedUntil <= now).

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.

func (*UnlockAccountTask) Run

func (t *UnlockAccountTask) Run(ctx context.Context) error

Run implements scheduler.Task.

Jump to

Keyboard shortcuts

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