emailpassword

package
v0.0.0-...-36ecd39 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const EmailVerificationExpiry = 15 * time.Minute
View Source
const PasswordResetExpiry = 1 * time.Hour

Variables

View Source
var (
	ErrInvalidEmail           = errors.New("invalid email")
	ErrPasswordTooShort       = errors.New("password too short")
	ErrPasswordTooLong        = errors.New("password too long")
	ErrInvalidEmailOrPassword = errors.New("invalid email or password")
)
View Source
var ErrEmailAlreadyVerified = errors.New("email already verified")
View Source
var ErrEmailMissing = errors.New("email missing")
View Source
var ErrEmailTaken = errors.New("email already registered")
View Source
var ErrInvalidCode = errors.New("invalid or expired code")
View Source
var ErrInvalidCurrentPassword = errors.New("current password is incorrect")
View Source
var ErrInvalidToken = errors.New("invalid or expired token")
View Source
var ErrPasswordBreached = errors.New("password found in data breach")
View Source
var ErrPasswordsDoNotMatch = errors.New("passwords do not match")
View Source
var ErrUserNotFound = errors.New("user not found")

Functions

func CheckPasswordBreach

func CheckPasswordBreach(password string) error

func DefaultResetPasswordEmailTemplate

func DefaultResetPasswordEmailTemplate(data ResetPasswordTemplateData) (mailer.Content, error)

func DefaultVerifyEmailTemplate

func DefaultVerifyEmailTemplate(data VerifyEmailTemplateData) (mailer.Content, error)

func GenerateVerificationCode

func GenerateVerificationCode() (string, error)

func HashPassword

func HashPassword(password string) (string, error)

func NormalizeEmail

func NormalizeEmail(email string) string

func ValidateEmail

func ValidateEmail(email string) error

func ValidatePassword

func ValidatePassword(password string) error

func ValidatePasswordWithMinLength

func ValidatePasswordWithMinLength(password string, minLength int) error

func VerifyPassword

func VerifyPassword(password, encoded string) bool

Types

type Client

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

func NewClient

func NewClient(cfg ClientConfig) (*Client, error)

func (*Client) ChangePasswordWithConfirmation

func (c *Client) ChangePasswordWithConfirmation(ctx context.Context, userID, currentPassword, newPassword, confirmPassword string) error

func (*Client) IssueEmailVerificationCode

func (c *Client) IssueEmailVerificationCode(ctx context.Context, userID string) (string, error)

func (*Client) Login

func (c *Client) Login(ctx context.Context, email, password string) (*User, error)

func (*Client) ResetPassword

func (c *Client) ResetPassword(ctx context.Context, token, newPassword, confirmPassword string) error

func (*Client) Signup

func (c *Client) Signup(ctx context.Context, email, password string) (*User, error)

func (*Client) StartPasswordReset

func (c *Client) StartPasswordReset(ctx context.Context, email string) (string, error)

func (*Client) VerifyEmailCode

func (c *Client) VerifyEmailCode(ctx context.Context, userID, code string) error

type ClientConfig

type ClientConfig struct {
	DB                           *sql.DB
	Mailer                       mailer.Mailer
	AppName                      string
	AppBaseURL                   string
	Emails                       EmailsConfig
	MinPasswordLength            int
	DisableBreachedPasswordCheck bool
	PasswordBreachCheckTimeout   time.Duration
	PasswordBreachCheckUserAgent string
	PasswordBreachChecker        PasswordBreachChecker
}

type EmailVerificationCode

type EmailVerificationCode struct {
	ID        string
	UserID    string
	Email     string
	CodeHash  []byte
	ExpiresAt time.Time
	CreatedAt time.Time
}

type EmailsConfig

type EmailsConfig struct {
	ResetPassword ResetPasswordTemplate
	VerifyEmail   VerifyEmailTemplate
}

type PasswordBreachCheckConfig

type PasswordBreachCheckConfig struct {
	Timeout   time.Duration
	UserAgent string
	Client    *http.Client
}

type PasswordBreachChecker

type PasswordBreachChecker func(ctx context.Context, password string) error

type PasswordResetToken

type PasswordResetToken struct {
	ID        string
	UserID    string
	TokenHash []byte
	ExpiresAt time.Time
	CreatedAt time.Time
}

type PasswordTooShortError

type PasswordTooShortError struct {
	MinLength int
}

func (PasswordTooShortError) Error

func (e PasswordTooShortError) Error() string

func (PasswordTooShortError) Is

func (e PasswordTooShortError) Is(target error) bool

type ResetPasswordTemplate

type ResetPasswordTemplate func(data ResetPasswordTemplateData) (mailer.Content, error)

type ResetPasswordTemplateData

type ResetPasswordTemplateData struct {
	AppName     string
	Email       string
	ResetURL    string
	ExpiresIn   time.Duration
	RequestedAt time.Time
}

type User

type User struct {
	ID            string
	Email         string
	EmailVerified bool
	CreatedAt     time.Time
}

type UserWithPassword

type UserWithPassword struct {
	User
	PasswordHash string
}

func GetUserPasswordByEmail

func GetUserPasswordByEmail(ctx context.Context, db *sql.DB, email string) (*UserWithPassword, error)

type VerifyEmailTemplate

type VerifyEmailTemplate func(data VerifyEmailTemplateData) (mailer.Content, error)

type VerifyEmailTemplateData

type VerifyEmailTemplateData struct {
	AppName     string
	Email       string
	Code        string
	ExpiresIn   time.Duration
	RequestedAt time.Time
}

Jump to

Keyboard shortcuts

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