Versions in this module Expand all Collapse all v0 v0.5.10 Oct 2, 2026 v0.5.8 Oct 2, 2026 v0.5.7 Oct 1, 2026 v0.5.6 Sep 17, 2026 v0.5.5 Sep 16, 2026 v0.5.4 Sep 16, 2026 v0.5.3 Sep 16, 2026 v0.5.2 Sep 16, 2026 v0.5.1 Sep 16, 2026 v0.5.0 Sep 14, 2026 v0.4.2 Sep 14, 2026 v0.4.1 Sep 14, 2026 v0.4.0 Sep 14, 2026 v0.3.0 Sep 14, 2026 v0.2.2 Sep 13, 2026 v0.2.1 Sep 13, 2026 v0.2.0 Sep 13, 2026 v0.1.0 Sep 13, 2026 Changes in this version + const ActionLogin + const ActionLogout + const ActionSettingReset + const ActionSettingSet + const ActionUserCreate + const ActionUserDelete + const ActionUserUpdate + const DefaultSessionTTL + const RoleAdmin + var ErrCodeRequired = errors.New("a one time code is required") + var ErrCodeReused = errors.New("the code has already been used") + var ErrInvalidCode = errors.New("invalid one time code") + var ErrNoSession = errors.New("session not found") + var ErrNoUser = errors.New("user not found") + var ErrSessionExpired = errors.New("the session has expired") + var ErrUserDisabled = errors.New("the account is disabled") + var ErrWrongPassword = errors.New("wrong password") + func HashPassword(password string) (string, error) + func NewSessionToken() (token, id string, err error) + func NewTOTPSecret() (string, error) + func NormalizeEmail(email string) string + func SessionID(token string) string + func TOTPCode(secret string, at time.Time) (string, error) + func TOTPURI(issuer, account, secret string) string + func VerifyPassword(hash, password string) error + func VerifyTOTP(secret, code string, now time.Time, lastCounter int64) (int64, error) + type AuditEntry struct + Action string + Actor string + At time.Time + Details string + ID int64 + IP string + Target string + type AuditRepo interface + Add func(ctx context.Context, e AuditEntry) error + List func(ctx context.Context, limit int, before int64) ([]AuditEntry, error) + type Auth struct + Now func() time.Time + func NewAuth(users UserRepo, sessions SessionRepo, ttl time.Duration) *Auth + func (a *Auth) Cleanup(ctx context.Context) (int, error) + func (a *Auth) CreateUser(ctx context.Context, email, password string, roles []string, twoFactor bool) (User, string, error) + func (a *Auth) Login(ctx context.Context, email, password, code, ip, userAgent string) (string, error) + func (a *Auth) Logout(ctx context.Context, token string) error + func (a *Auth) Session(ctx context.Context, token string) (User, Session, error) + func (a *Auth) SetPassword(ctx context.Context, id int64, password string) error + type MemoryStore struct + func NewMemoryStore() *MemoryStore + func (s *MemoryStore) Audit() AuditRepo + func (s *MemoryStore) ByEmail(_ context.Context, email string) (User, error) + func (s *MemoryStore) ByID(_ context.Context, id int64) (User, error) + func (s *MemoryStore) Create(_ context.Context, u User) (User, error) + func (s *MemoryStore) Delete(_ context.Context, id int64) error + func (s *MemoryStore) List(context.Context) ([]User, error) + func (s *MemoryStore) Sessions() SessionRepo + func (s *MemoryStore) Update(_ context.Context, u User) error + func (s *MemoryStore) Users() UserRepo + type Session struct + CreatedAt time.Time + ExpiresAt time.Time + ID string + IP string + UserAgent string + UserID int64 + type SessionRepo interface + ByID func(ctx context.Context, id string) (Session, error) + Create func(ctx context.Context, s Session) error + Delete func(ctx context.Context, id string) error + DeleteByUser func(ctx context.Context, userID int64) error + DeleteExpired func(ctx context.Context, now time.Time) (int, error) + type User struct + CreatedAt time.Time + Disabled bool + Email string + ID int64 + LastLoginAt time.Time + PasswordHash string + Roles []string + TOTPCounter int64 + TOTPSecret string + func (u User) Has(role string) bool + func (u User) HasAny(roles []string) bool + func (u User) TwoFactor() bool + type UserRepo interface + ByEmail func(ctx context.Context, email string) (User, error) + ByID func(ctx context.Context, id int64) (User, error) + Create func(ctx context.Context, u User) (User, error) + Delete func(ctx context.Context, id int64) error + List func(ctx context.Context) ([]User, error) + Update func(ctx context.Context, u User) error