Documentation
¶
Index ¶
- Variables
- func GeneratePassword(length int) (string, error)
- func HashPassword(password string) (string, error)
- func NeedsRehash(hashedPassword string) bool
- func ValidateEmail(email string) error
- func ValidatePassword(password string) error
- func VerifyPassword(hashedPassword, password string) error
- type Claims
- type JWTManager
Constants ¶
This section is empty.
Variables ¶
var (
ErrEmailInvalid = errors.New("please enter a valid email address")
)
var (
ErrPasswordInvalid = errors.New("password must be at least 12 characters with mixed case, numbers, and special characters")
)
Functions ¶
func GeneratePassword ¶
GeneratePassword generates a cryptographically secure random password using crypto/rand. The length must be >= 12. If 0 is passed, defaults to 16.
func HashPassword ¶
HashPassword generates an Argon2id hash from a plain text password using PHC string format
func NeedsRehash ¶
NeedsRehash returns true if the hash uses an outdated algorithm or parameters and should be re-hashed with the current recommended settings.
func ValidateEmail ¶
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 ¶
ValidatePassword checks if a password meets security criteria
func VerifyPassword ¶
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