Skip to content

Commit

Permalink
fixed username validator (goharbor#239)
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Eschenbach <[email protected]>
  • Loading branch information
Roaster05 authored and qcserestipy committed Dec 22, 2024
1 parent 08d7811 commit b3ccfba
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/utils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ func FormatSize(size int64) string {
return fmt.Sprintf("%.2fMiB", mbSize)
}

// ValidateUserName checks if the username is valid by length and allowed characters.
func ValidateUserName(username string) bool {
pattern := `^[a-zA-Z0-9]{1,255}$`
re := regexp.MustCompile(pattern)
return re.MatchString(username)
username = strings.TrimSpace(username)
return len(username) >= 1 && len(username) <= 255 && !strings.ContainsAny(username, `,"~#%$`)
}

func ValidateEmail(email string) bool {
Expand Down

0 comments on commit b3ccfba

Please sign in to comment.