passwordreset

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 8 Imported by: ? 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 passwordreset manages password recovery with emailed tokens.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAttemptBlocked  = errors.New("password reset attempt blocked")
	ErrConflict        = errors.New("password reset conflict")
	ErrInactiveToken   = errors.New("password reset token is inactive")
	ErrInvalidConfig   = errors.New("invalid password reset configuration")
	ErrInvalidPassword = errors.New("invalid replacement password")
	ErrInvalidRecord   = errors.New("invalid password reset record")
	ErrInvalidToken    = token.ErrInvalidToken
	ErrNotFound        = errors.New("password reset record not found")
)

Functions

This section is empty.

Types

type Attempt

type Attempt struct {
	Operation Operation
	Email     string
	SourceKey string
}

type AttemptGuard

type AttemptGuard interface {
	Check(ctx context.Context, attempt Attempt) error
}

type Config

type Config struct {
	Lifetime         time.Duration
	Sender           Sender
	Passwords        Passwords
	ValidatePassword PasswordValidator
	AttemptGuard     AttemptGuard
	SecurityEvents   SecurityEventSink
	NormalizeEmail   emailaddress.Normalizer
	Now              func() time.Time
}

type EventType

type EventType string
const (
	EventMessageSent EventType = "password_reset_message_sent"
	EventResetFailed EventType = "password_reset_failed"
	EventReset       EventType = "password_reset"
)

type Manager

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

func NewManager

func NewManager(store Store, config Config) (*Manager, error)

func (*Manager) Request

func (manager *Manager) Request(ctx context.Context, input RequestInput) error

func (*Manager) Reset

func (manager *Manager) Reset(ctx context.Context, input ResetInput) (User, error)

type Message

type Message struct {
	UserID    string
	Email     string
	Token     string
	URL       string
	ExpiresAt time.Time
}

type Operation

type Operation string
const (
	OperationRequest Operation = "request"
	OperationReset   Operation = "reset"
)

type PasswordValidator

type PasswordValidator func(plainPassword string) error

type Passwords

type Passwords interface {
	Hash(plainPassword string) (string, error)
}

type Record

type Record struct {
	UserID    string
	Email     string
	TokenHash TokenHash
	CreatedAt time.Time
	ExpiresAt time.Time
}

type RequestInput

type RequestInput struct {
	Email     string
	SourceKey string
}

type ResetInput

type ResetInput struct {
	Token       string
	NewPassword string
	SourceKey   string
}

type SecurityEvent

type SecurityEvent struct {
	Type       EventType
	SubjectID  string
	SourceKey  string
	OccurredAt time.Time
}

type SecurityEventSink

type SecurityEventSink interface {
	Record(ctx context.Context, event SecurityEvent)
}

type Sender

type Sender interface {
	SendPasswordReset(ctx context.Context, message Message) error
}

type Store

type Store interface {
	FindUserByEmail(ctx context.Context, normalizedEmail string) (User, error)
	Issue(ctx context.Context, record Record) error
	ResetPassword(
		ctx context.Context,
		tokenHash TokenHash,
		passwordHash string,
		resetAt time.Time,
	) (User, error)
}

Issue replaces the user's earlier token. ResetPassword accepts the current token once before expiry, changes the password, and invalidates the user's other reset tokens in one storage operation.

type TokenHash

type TokenHash token.Hash

type User

type User struct {
	ID    string
	Email string
}

Jump to

Keyboard shortcuts

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