init
Some checks failed
Build and Release / release (push) Failing after 51s

This commit is contained in:
2026-03-25 22:29:07 +07:00
parent eedd300861
commit 79199f627d
65 changed files with 3215 additions and 689 deletions

39
pkg/constant/regex.go Normal file
View File

@@ -0,0 +1,39 @@
package constant
import (
"errors"
"regexp"
)
var (
// Password components (Go-compatible)
hasUpper = regexp.MustCompile(`[A-Z]`)
hasLower = regexp.MustCompile(`[a-z]`)
hasNumber = regexp.MustCompile(`\d`)
hasSpecial = regexp.MustCompile(`[!@#$%^&*()_+{}|:<>?~-]`)
// Standard Regexes
PHONE_NUMBER_REGEX = regexp.MustCompile(`^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$`)
EMAIL_REGEX = regexp.MustCompile(`^[a-z0-9._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,4}$`)
YOUTUBE_VIDEO_ID_REGEX = regexp.MustCompile(`(?:\/|v=|\/v\/|embed\/|watch\?v=|watch\?.+&v=)([\w-]{11})`)
BANK_INPUT = regexp.MustCompile(`[__]{2,}`)
)
func ValidatePassword(password string) error {
if len(password) < 8 {
return errors.New("password must be at least 8 characters long")
}
if !hasUpper.MatchString(password) {
return errors.New("password must contain at least one uppercase letter")
}
if !hasLower.MatchString(password) {
return errors.New("password must contain at least one lowercase letter")
}
if !hasNumber.MatchString(password) {
return errors.New("password must contain at least one number")
}
if !hasSpecial.MatchString(password) {
return errors.New("password must contain at least one special character")
}
return nil
}

View File

@@ -22,6 +22,13 @@ func CheckValidRole(r Role) bool {
return r == ADMIN || r == MOD || r == HISTORIAN || r == USER || r == BANNED
}
func (r Role) ToSlice() []string {
return []string{r.String()}
func ParseRole(s string) (Role, bool) {
r := Role(s)
if CheckValidRole(r) {
return r, true
}
return "", false
}
func (r Role) ToSlice() []Role {
return []Role{r}
}