diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-10-29 03:40:09 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-10-29 03:40:09 +0900 |
| commit | 274686d10d3386a41f8fb6bc3363269a734afe0e (patch) | |
| tree | 59ce81d5617cf5e1f67b819dab49b83b71d8ff93 /internal/validate/username.go | |
| parent | 65342d588ff061d2130e6379d86a26be90c908ae (diff) | |
internal/validate: relocate from app
These are free of the dispatcher from internal/app. This change relocates them into their own package.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/validate/username.go')
| -rw-r--r-- | internal/validate/username.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/internal/validate/username.go b/internal/validate/username.go new file mode 100644 index 00000000..2249cd27 --- /dev/null +++ b/internal/validate/username.go @@ -0,0 +1,12 @@ +package validate + +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) +} |
