Documentation
¶
Index ¶
Constants ¶
const ( DefaultResetTokenExpiry = 12 * time.Hour DefaultResetTokenLength = 32 )
Variables ¶
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.
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 (*Handler) HandlePasswordReset ¶
HandlePasswordReset handles a password reset request.
type PasswordResetRequestMessagePayload ¶
type PasswordResetRequestMessagePayload struct {
Token string
}
ResetTokenMessagePayload is the payload for the reset token message.