From c16640d332f204a66db95671d05e6dbbab91c5e5 Mon Sep 17 00:00:00 2001 From: Prasanth B <89722848+bupd@users.noreply.github.com> Date: Tue, 26 Nov 2024 20:33:26 +0530 Subject: [PATCH] fix-username validation (#265) Signed-off-by: bupd Signed-off-by: Patrick Eschenbach --- pkg/utils/helper.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/utils/helper.go b/pkg/utils/helper.go index 22863f5e..ba11029e 100644 --- a/pkg/utils/helper.go +++ b/pkg/utils/helper.go @@ -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 {