reset

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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