Documentation
¶
Index ¶
- func IsIncomingTokenValid(token string, tokenMaxLength int) error
- type EmailValidation
- type EmailValidationInterface
- type OTPValidation
- type OTPValidationInterface
- type PasswordValidation
- func (pv *PasswordValidation) IsPasswordStrengthEnough(password string) bool
- func (pv *PasswordValidation) PasswordContainsDigit(password string) bool
- func (pv *PasswordValidation) PasswordContainsLowercase(password string) bool
- func (pv *PasswordValidation) PasswordContainsSpecialChar(password string) bool
- func (pv *PasswordValidation) PasswordContainsUnauthorizedWord(password string) bool
- func (pv *PasswordValidation) PasswordContainsUppercase(password string) bool
- func (pv *PasswordValidation) PasswordHasMinLength(password string) bool
- func (pv *PasswordValidation) SetMinLength(minLength int)
- func (pv *PasswordValidation) SetUnauthorizedWords(unauthorizedWords []string)
- type PasswordValidationInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsIncomingTokenValid ¶
IsIncomingTokenValid validates the format of an incoming token string. Performs basic validation checks for token length and emptiness.
Validations:
- Non-empty: Token must contain at least one character
- Length check: Token must not exceed tokenMaxLength
This is a generic validation function used by multiple services:
- RefreshTokenService: tokenMaxLength = 255
- PasswordResetService: tokenMaxLength = 32
Parameters:
- token: The token string to validate
- tokenMaxLength: Maximum allowed length for the token
Returns:
- error: Validation error with descriptive message, nil if valid
Example:
if err := validation.IsIncomingTokenValid(token, 255); err != nil {
return fmt.Errorf("invalid token format: %w", err)
}
Types ¶
type EmailValidation ¶
type EmailValidation struct {
// contains filtered or unexported fields
}
EmailValidation maintains a compiled regular expression for efficient email address pattern matching operations.
func NewEmailValidation ¶
func NewEmailValidation() *EmailValidation
NewEmailValidation creates a new email validator with a pre-compiled RFC-compliant regular expression pattern. The validator accepts standard email formats including alphanumeric characters, dots, underscores, percent signs, plus signs, and hyphens in the local part, and alphanumeric characters, dots, and hyphens in the domain part.
func (*EmailValidation) IsValidEmail ¶
func (ev *EmailValidation) IsValidEmail(email string) bool
IsValidEmail validates whether the provided string conforms to standard email address format requirements. The validation ensures the presence of a local part, @ symbol, domain name, and top-level domain with at least 2 characters.
Returns true if the email address is properly formatted.
type EmailValidationInterface ¶
EmailValidationInterface defines the email validation contract, enabling dependency injection and testing scenarios.
type OTPValidation ¶
type OTPValidation struct {
// contains filtered or unexported fields
}
OTPValidation provides validation methods for OTP codes. Ensures OTP codes are exactly 6 numeric digits.
func NewOTPValidation ¶
func NewOTPValidation() *OTPValidation
NewOTPValidation creates a new OTP validator instance. The validator ensures OTP codes are exactly 6 numeric digits.
Returns:
- *OTPValidation: Validator ready for use
Example:
validator := validation.NewOTPValidation()
if validator.ISOTPValid("123456") {
log.Println("Valid OTP")
}
func (*OTPValidation) ISOTPValid ¶
func (ov *OTPValidation) ISOTPValid(otp string) bool
ISOTPValid performs complete OTP validation. Checks both length (6 characters) and format (numeric only).
Valid examples: "123456", "000042", "999999" Invalid examples: "12345", "1234567", "12345a", "abc123"
Parameters:
- otp: The OTP code to validate
Returns:
- bool: true if OTP is valid (6 numeric digits), false otherwise
Example:
validator := validation.NewOTPValidation()
if validator.ISOTPValid("123456") {
// OTP format is valid, proceed with verification
}
func (*OTPValidation) OTPHasLength ¶
func (ov *OTPValidation) OTPHasLength(otp string) bool
OTPHasLength checks if the OTP is exactly 6 characters long.
Parameters:
- otp: The OTP code to validate
Returns:
- bool: true if length is exactly 6, false otherwise
func (*OTPValidation) OTPOnlyContainsDigits ¶
func (ov *OTPValidation) OTPOnlyContainsDigits(otp string) bool
OTPOnlyContainsDigits checks if the OTP contains only numeric digits. Validates using a pre-compiled regex pattern (^\d{6}$).
Parameters:
- otp: The OTP code to validate
Returns:
- bool: true if OTP is 6 numeric digits, false otherwise
type OTPValidationInterface ¶
type OTPValidationInterface interface {
OTPHasLength(otp string) bool
OTPOnlyContainsDigits(otp string) bool
ISOTPValid(otp string) bool
}
OTPValidationInterface defines the methods for OTP validation.
type PasswordValidation ¶
type PasswordValidation struct {
// contains filtered or unexported fields
}
PasswordValidation maintains password validation configuration and compiled regular expressions for efficient pattern matching operations.
func NewPasswordValidation ¶
func NewPasswordValidation() *PasswordValidation
NewPasswordValidation creates a new password validator with secure defaults. The validator is initialized with a minimum length of 8 characters, an empty unauthorized words list, and pre-compiled regex patterns for optimal performance.
func (*PasswordValidation) IsPasswordStrengthEnough ¶
func (pv *PasswordValidation) IsPasswordStrengthEnough(password string) bool
IsPasswordStrengthEnough performs comprehensive validation against all configured rules. The password must satisfy ALL requirements:
- Contains lowercase letters
- Contains uppercase letters
- Contains digits
- Contains special characters
- Meets minimum length
- Not found in unauthorized words list
Returns true if the password passes all validation rules.
func (*PasswordValidation) PasswordContainsDigit ¶
func (pv *PasswordValidation) PasswordContainsDigit(password string) bool
PasswordContainsDigit verifies the presence of numeric digits (0-9) in the provided password string.
func (*PasswordValidation) PasswordContainsLowercase ¶
func (pv *PasswordValidation) PasswordContainsLowercase(password string) bool
PasswordContainsLowercase verifies the presence of lowercase letters (a-z) in the provided password string.
func (*PasswordValidation) PasswordContainsSpecialChar ¶
func (pv *PasswordValidation) PasswordContainsSpecialChar(password string) bool
PasswordContainsSpecialChar verifies the presence of special characters in the provided password string. Accepted characters include: !@#$%^&*()-+={}[]|\:;"'<>,.?/~_
func (*PasswordValidation) PasswordContainsUnauthorizedWord ¶
func (pv *PasswordValidation) PasswordContainsUnauthorizedWord(password string) bool
PasswordContainsUnauthorizedWord checks if the password exactly matches any blacklisted word in the unauthorized words list. Returns true if the password is found in the blacklist.
func (*PasswordValidation) PasswordContainsUppercase ¶
func (pv *PasswordValidation) PasswordContainsUppercase(password string) bool
PasswordContainsUppercase verifies the presence of uppercase letters (A-Z) in the provided password string.
func (*PasswordValidation) PasswordHasMinLength ¶
func (pv *PasswordValidation) PasswordHasMinLength(password string) bool
PasswordHasMinLength validates that the password meets the configured minimum length requirement.
func (*PasswordValidation) SetMinLength ¶
func (pv *PasswordValidation) SetMinLength(minLength int)
SetMinLength configures the minimum acceptable password length. Values below 8 characters are silently rejected to maintain baseline security standards.
func (*PasswordValidation) SetUnauthorizedWords ¶
func (pv *PasswordValidation) SetUnauthorizedWords(unauthorizedWords []string)
SetUnauthorizedWords defines a blacklist of prohibited passwords. Validation performs exact string matching and is case-sensitive.
type PasswordValidationInterface ¶
type PasswordValidationInterface interface {
SetMinLength(minLength int)
PasswordContainsLowercase(password string) bool
PasswordContainsUppercase(password string) bool
PasswordContainsDigit(password string) bool
PasswordContainsSpecialChar(password string) bool
PasswordHasMinLength(password string) bool
IsPasswordStrengthEnough(password string) bool
}
PasswordValidationInterface defines the complete validation contract, enabling dependency injection and testing scenarios.