ms-auth/internal/lib/validation.go
Vyacheslav1557 5af1a98b49 feat: init
2024-07-15 02:26:34 +05:00

45 lines
736 B
Go

package lib
import (
"net/mail"
)
func ValidPassword(str string) error {
if len(str) < 5 {
return ErrTooShortPassword
}
if len(str) > 70 {
return ErrTooLongPassword
}
return nil
}
func ValidUsername(str string) error {
if len(str) < 5 {
return ErrTooShortUsername
}
if len(str) > 70 {
return ErrTooLongUsername
}
if err := ValidEmail(str); err == nil {
return ErrBadUsername
}
return nil
}
func ValidEmail(str string) error {
emailAddress, err := mail.ParseAddress(str)
if err != nil || emailAddress.Address != str {
return ErrBadEmail
}
return nil
}
func ValidRole(role int32) error {
switch role {
case RoleSpectator, RoleParticipant, RoleModerator, RoleAdmin:
return nil
}
return ErrBadRole
}