auth

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) error

func HashPassword

func HashPassword(password string) (string, error)

Types

type Session

type Session struct {
	UserAgent string     `json:"user_agent" db:"user_agent"`
	ID        string     `json:"id" db:"id"`
	UserID    string     `json:"user_id" db:"user_id"`
	TokenHash string     `json:"-" db:"token_hash"`
	ExpiresAt *time.Time `json:"expires_at" db:"expires_at"`
	CreatedAt time.Time  `json:"created_at" db:"created_at"`
	LastUsed  *time.Time `json:"last_used" db:"last_used"`
}

type Store

type Store interface {
	Authenticate(username, password string) (*User, error)
	CreateUser(username, password string) (*User, error)
	GetUserByUsername(username string) (*User, error)
	GetUserByID(userID string) (*User, error)

	CreateSession(userAgent, userID, tokenHash string) (*Session, error)
	GetSession(id string) (*Session, error)
	GetSessionByHash(tokenHash string) (*Session, error)
	UpdateSessionLastUsed(sessionID string) error
	DeleteSession(sessionID string) error
	IsSessionExpired(session *Session) bool
}

func NewStore

func NewStore(db *sql.DB) Store

type User

type User struct {
	ID           string `json:"id"`
	Username     string `json:"username"`
	PasswordHash string `json:"-"`
	CreatedAt    string `json:"created_at"`
}

Jump to

Keyboard shortcuts

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