Skip to content

Commit

Permalink
fix-username validation (goharbor#265)
Browse files Browse the repository at this point in the history
Signed-off-by: bupd <bupdprasanth@gmail.com>
Signed-off-by: Patrick Eschenbach <patrickeschenbach96@gmail.com>
  • Loading branch information
bupd authored and qcserestipy committed Dec 22, 2024
1 parent d867478 commit c16640d
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 c16640d

Please sign in to comment.