reset

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package reset provides password reset token management functionality

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateConfig

func ValidateConfig(cfg *Config) error

ValidateConfig validates a password reset token configuration

Types

type CleanupService

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

CleanupService handles periodic cleanup of expired password reset tokens

func NewCleanupService

func NewCleanupService(tokenManager *TokenManager, interval time.Duration, logger *slog.Logger) *CleanupService

NewCleanupService creates a new cleanup service

func (*CleanupService) RunOnce

func (cs *CleanupService) RunOnce(ctx context.Context) error

RunOnce performs a single cleanup operation (useful for testing or manual cleanup)

func (*CleanupService) Start

func (cs *CleanupService) Start(ctx context.Context)

Start begins the cleanup service in a background goroutine

func (*CleanupService) Stop

func (cs *CleanupService) Stop()

Stop gracefully stops the cleanup service

type Config

type Config struct {
	TokenLength      int           // Length of generated tokens (default: 32)
	TokenLifetime    time.Duration // How long tokens are valid (default: 1 hour)
	CleanupInterval  time.Duration // How often to clean up expired tokens (default: 24 hours)
	MaxTokensPerUser int           // Maximum active tokens per user (default: 3)
}

Config contains configuration for password reset tokens

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default configuration for password reset tokens

func LoadConfigFromViper

func LoadConfigFromViper() (*Config, error)

LoadConfigFromViper loads password reset token configuration from viper settings

type TokenManager

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

TokenManager handles password reset token operations

func NewTokenManager

func NewTokenManager(queries models.Querier, config *Config) *TokenManager

NewTokenManager creates a new password reset token manager

func (*TokenManager) CleanupExpiredTokens

func (tm *TokenManager) CleanupExpiredTokens(ctx context.Context) error

CleanupExpiredTokens removes expired tokens from the database

func (*TokenManager) CreateToken

func (tm *TokenManager) CreateToken(ctx context.Context, userID int32) (*models.PasswordResetToken, error)

CreateToken creates a new password reset token for the given user

func (*TokenManager) GetTokenStats

GetTokenStats returns statistics about password reset tokens

func (*TokenManager) GetTokenTimeRemaining

func (tm *TokenManager) GetTokenTimeRemaining(token *models.PasswordResetToken) time.Duration

GetTokenTimeRemaining returns the time remaining before a token expires

func (*TokenManager) InvalidateUserTokens

func (tm *TokenManager) InvalidateUserTokens(ctx context.Context, userID int32) error

InvalidateUserTokens invalidates all active password reset tokens for a user

func (*TokenManager) UseToken

func (tm *TokenManager) UseToken(ctx context.Context, token string) error

UseToken marks a password reset token as used

func (*TokenManager) ValidateToken

func (tm *TokenManager) ValidateToken(ctx context.Context, token string) (*models.PasswordResetToken, error)

ValidateToken validates a password reset token and returns the token if valid

Jump to

Keyboard shortcuts

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