shieldpasswordreset

package
v0.0.0-...-1d36bab Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultResetTokenExpiry = 12 * time.Hour
	DefaultResetTokenLength = 32
)

Variables

View Source
var ErrUsedPasswordResetToken = errors.New(
	"shieldpasswordreset: password reset token has been used",
)

ErrUsedPasswordResetToken is returned when the password reset token has already been used.

Functions

func WithPasswordHasher

func WithPasswordHasher(hasher shieldpassword.PasswordHasher) func(*Config)

WithPasswordHasher configures the password hasher.

When setting a password hasher make sure to set it across all modules, such as user registrration, password reset and password verification.

Types

type Config

type Config struct {
	PasswordHasher shieldpassword.PasswordHasher // optional
	Logger         *slog.Logger                  // optional

	// TokenLength set the length of the reset token.
	//
	// Defaults to DefaultResetTokenExpiry.
	TokenLength int // optional

	// TokenExpiryIn set the expiry time of the reset token.
	//
	// Defaults to DefaultResetTokenLength
	TokenExpiryIn time.Duration // optional
}

Config is the configuration for the password handler.

Make sure to use the NewConfig function to create a new config, instead of instantiating the struct directly.

func NewConfig

func NewConfig(opts ...func(*Config)) *Config

NewConfig creates a new config.

type Handler

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

Handler handles password reset requests.

It is a general enough implementation so it can be used for different communication methods.

Check out the FormHandler for a ready to use implementation that handles HTTP form requests.

func NewHandler

func NewHandler(
	pool *pgxpool.Pool,
	sender shieldsender.Sender,
	config *Config,
) *Handler

func (*Handler) HandlePasswordReset

func (h *Handler) HandlePasswordReset(
	ctx context.Context,
	email string,
) error

HandlePasswordReset handles a password reset request.

func (*Handler) HandlePasswordResetConfirm

func (h *Handler) HandlePasswordResetConfirm(
	ctx context.Context,
	password, tokStr string,
) error

type PasswordResetRequestMessagePayload

type PasswordResetRequestMessagePayload struct {
	Token string
}

ResetTokenMessagePayload is the payload for the reset token message.

Jump to

Keyboard shortcuts

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