auth

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 14 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

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmailInvalid = errors.New("please enter a valid email address")
)
View Source
var (
	ErrPasswordInvalid = errors.New("password must be at least 12 characters with mixed case, numbers, and special characters")
)

Functions

func GeneratePassword

func GeneratePassword(length int) (string, error)

GeneratePassword generates a cryptographically secure random password using crypto/rand. The length must be >= 12. If 0 is passed, defaults to 16.

func HashPassword

func HashPassword(password string) (string, error)

HashPassword generates an Argon2id hash from a plain text password using PHC string format

func NeedsRehash

func NeedsRehash(hashedPassword string) bool

NeedsRehash returns true if the hash uses an outdated algorithm or parameters and should be re-hashed with the current recommended settings.

func ValidateEmail

func ValidateEmail(email string) error

ValidateEmail checks if an email address has a valid format Note: SQL injection is mitigated by using parameterized queries in the repository layer (#10)

func ValidatePassword

func ValidatePassword(password string) error

ValidatePassword checks if a password meets security criteria

func VerifyPassword

func VerifyPassword(hashedPassword, password string) error

VerifyPassword compares a plain text password with a stored hash. It supports both Argon2id (PHC format) and bcrypt hashes for backward compatibility.

Types

type Claims

type Claims struct {
	UserID   string `json:"user_id"`
	Username string `json:"username"`
	Role     string `json:"role"`
	jwt.RegisteredClaims
}

Claims represents JWT claims structure

type JWTManager

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

JWTManager handles JWT token generation and validation

func NewJWTManager

func NewJWTManager(secretKey string) *JWTManager

NewJWTManager creates a new JWT manager

func (*JWTManager) GenerateToken

func (j *JWTManager) GenerateToken(userID, username, role string) (string, error)

GenerateToken creates a new JWT token for a user

func (*JWTManager) ValidateToken

func (j *JWTManager) ValidateToken(tokenString string) (*Claims, error)

ValidateToken validates a JWT token and returns the claims

Jump to

Keyboard shortcuts

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