forked from security/hakurei
Use the default value of NAME_REGEX from adduser. Should not hurt compatibility while being less strict. Signed-off-by: Ophestra <cat@gensokyo.uk>
13 lines
365 B
Go
13 lines
365 B
Go
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)
|
|
}
|