auth

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCookieName = "emerald_session"
	DefaultSessionTTL = 24 * time.Hour
)

Variables

View Source
var ErrInvalidCredentials = errors.New("invalid credentials")
View Source
var ErrRateLimited = errors.New("too many login attempts")

Functions

func HashPassword added in v1.11.1

func HashPassword(password string) (string, error)

func IsPasswordHash added in v1.11.1

func IsPasswordHash(value string) bool

func VerifyPasswordHash added in v1.11.1

func VerifyPasswordHash(stored string, password string) (bool, error)

Types

type Config

type Config struct {
	SessionTTL   time.Duration
	CookieName   string
	SessionStore SessionStore
}

type LegacyPasswordStore added in v1.11.1

type LegacyPasswordStore interface {
	VerifyLegacyPassword(stored string, provided string) (bool, error)
}

type Service

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

func NewService

func NewService(users UserStore, cfg Config) *Service

func (*Service) Authenticate

func (s *Service) Authenticate(ctx context.Context, username string, password string) (*models.User, error)

func (*Service) CookieName

func (s *Service) CookieName() string

func (*Service) Login

func (s *Service) Login(ctx context.Context, username string, password string) (string, Session, error)

func (*Service) Logout

func (s *Service) Logout(token string)

func (*Service) RevokeUserSessions

func (s *Service) RevokeUserSessions(userID string)

func (*Service) Session

func (s *Service) Session(token string) (Session, bool)

type Session

type Session struct {
	UserID       string
	Username     string
	IsSuperAdmin bool
	ExpiresAt    time.Time
}

type SessionStore added in v1.11.1

type SessionStore interface {
	Create(ctx context.Context, token string, session Session) error
	GetByToken(ctx context.Context, token string, now time.Time) (Session, bool, error)
	Delete(ctx context.Context, token string) error
	DeleteByUserID(ctx context.Context, userID string) error
}

type UserStore

type UserStore interface {
	GetByUsername(ctx context.Context, username string) (*models.User, error)
	UpdatePassword(ctx context.Context, id string, password string) error
}

Jump to

Keyboard shortcuts

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