internal/app: less strict username regex
All checks were successful
Test / Create distribution (push) Successful in 32s
Test / Sandbox (push) Successful in 1m50s
Test / Hpkg (push) Successful in 3m34s
Test / Sandbox (race detector) (push) Successful in 4m8s
Test / Hakurei (race detector) (push) Successful in 2m46s
Test / Hakurei (push) Successful in 2m15s
Test / Flake checks (push) Successful in 1m29s
All checks were successful
Test / Create distribution (push) Successful in 32s
Test / Sandbox (push) Successful in 1m50s
Test / Hpkg (push) Successful in 3m34s
Test / Sandbox (race detector) (push) Successful in 4m8s
Test / Hakurei (race detector) (push) Successful in 2m46s
Test / Hakurei (push) Successful in 2m15s
Test / Flake checks (push) Successful in 1m29s
Use the default value of NAME_REGEX from adduser. Should not hurt compatibility while being less strict. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
12
internal/app/username.go
Normal file
12
internal/app/username.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package app
|
||||
|
||||
import "regexp"
|
||||
|
||||
// nameRegex is the default NAME_REGEX value from adduser.
|
||||
var nameRegex = regexp.MustCompilePOSIX(`^[a-zA-Z][a-zA-Z0-9_-]*\$?$`)
|
||||
|
||||
// isValidUsername returns whether the argument is a valid username
|
||||
func isValidUsername(username string) bool {
|
||||
return len(username) < sysconf(_SC_LOGIN_NAME_MAX) &&
|
||||
nameRegex.MatchString(username)
|
||||
}
|
||||
Reference in New Issue
Block a user