diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-08-28 00:22:55 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-08-28 00:22:55 +0900 |
| commit | 1be8de6f5ca4c7e40f5999ce4f960010fc36acb1 (patch) | |
| tree | 5e8b48cc9fdef7f487d9356d21fdc66eb4edf847 /internal/app/username.go | |
| parent | 0f41d9667133401f48fb54174cb2b120ed7a769c (diff) | |
internal/app: less strict username regex
Use the default value of NAME_REGEX from adduser. Should not hurt compatibility while being less strict.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/app/username.go')
| -rw-r--r-- | internal/app/username.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/internal/app/username.go b/internal/app/username.go new file mode 100644 index 00000000..566daf5f --- /dev/null +++ b/internal/app/username.go @@ -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) +} |
