Skip to content

Commit 2bac524

Browse files
authored
Merge pull request #112 from deploymenttheory/dev
Refactor username validation to include password safe special characters
2 parents 9e83c79 + 96bce32 commit 2bac524

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

httpclient/httpclient_auth_validation.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ func IsValidClientSecret(clientSecret string) (bool, string) {
4040
return true, ""
4141
}
4242

43-
// IsValidUsername checks if the provided username meets your application's validation criteria.
43+
// IsValidUsername checks if the provided username meets password safe validation criteria.
4444
// Returns true if valid, along with an empty error message; otherwise, returns false with an error message.
4545
func IsValidUsername(username string) (bool, string) {
46-
if regexp.MustCompile(`^[a-zA-Z0-9]+$`).MatchString(username) {
46+
// Extended regex to include a common set of password safe special characters
47+
usernameRegex := `^[a-zA-Z0-9!@#$%^&*()_\-\+=\[\]{\}\\|;:'",<.>/?]+$`
48+
if regexp.MustCompile(usernameRegex).MatchString(username) {
4749
return true, ""
4850
}
49-
return false, "Username must contain only alphanumeric characters."
51+
return false, "Username must contain only alphanumeric characters and password safe special characters (!@#$%^&*()_-+=[{]}\\|;:'\",<.>/?)."
5052
}
5153

5254
// IsValidPassword checks if the provided password meets your application's validation criteria.

0 commit comments

Comments
 (0)