auth

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	DefaultPrefix = "clh_"
)

Variables

This section is empty.

Functions

func CheckPassword

func CheckPassword(hash, password string) bool

CheckPassword verifies a plaintext password against a bcrypt hash.

func ExtractPrefix

func ExtractPrefix(rawToken string) string

ExtractPrefix extracts the prefix portion used for fast DB lookup.

func GenerateToken

func GenerateToken(prefix string) (string, string, string, error)

GenerateToken creates a new API token with the clh_ prefix. Returns (rawToken, prefix, tokenHash).

func HashPassword

func HashPassword(password string) (string, error)

HashPassword hashes a plaintext password using bcrypt.

func HashToken

func HashToken(rawToken string) string

HashToken returns the SHA-256 hex hash of a raw token.

Types

type Service

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

func NewService

func NewService(tokenRepo *repository.TokenRepo, userRepo *repository.UserRepo) *Service

func (*Service) CreateToken

func (s *Service) CreateToken(ctx context.Context, userID uuid.UUID, label string) (string, *model.APIToken, error)

CreateToken generates a new API token for a user.

func (*Service) Login

func (s *Service) Login(ctx context.Context, handle, password string) (string, *model.User, error)

Login validates a handle+password, and returns a new API token for the session.

func (*Service) SetPassword

func (s *Service) SetPassword(ctx context.Context, userID uuid.UUID, password string) error

SetPassword sets a user's password hash.

func (*Service) ValidateToken

func (s *Service) ValidateToken(ctx context.Context, rawToken string) (*model.User, error)

ValidateToken validates a raw token and returns the associated user.

Jump to

Keyboard shortcuts

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