aboutsummaryrefslogtreecommitdiff
path: root/internal/player/validate.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-11 04:46:27 -0400
committerhistoria <[not public]>2026-06-11 08:58:37 +0000
commit1b9e2da3b3c438d8dc53d3489725dd5ba0022777 (patch)
tree62264f24420bf4cfaa734942c65cc8dd45ba3d3b /internal/player/validate.go
parent06c02a697e5daf8832a462de5970dd4c0e13a02c (diff)
downloadthehouseoficarus-1b9e2da3b3c438d8dc53d3489725dd5ba0022777.tar.gz
feat: web client, get/drop updates and fixes
Diffstat (limited to 'internal/player/validate.go')
-rw-r--r--internal/player/validate.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/internal/player/validate.go b/internal/player/validate.go
new file mode 100644
index 0000000..63f40d2
--- /dev/null
+++ b/internal/player/validate.go
@@ -0,0 +1,37 @@
+package player
+
+import (
+ "fmt"
+ "regexp"
+ "unicode"
+)
+
+var validNameRE = regexp.MustCompile(`^[A-Za-z0-9 ]{1,30}$`)
+
+func ValidName(name string) error {
+ if !validNameRE.MatchString(name) {
+ return fmt.Errorf("name must be 1-30 alphanumeric characters or spaces")
+ }
+ return nil
+}
+
+func ValidPassword(pw string) error {
+ if len(pw) > 128 {
+ return fmt.Errorf("Password too long.")
+ }
+ return nil
+}
+
+func StripControl(input string) string {
+ runes := make([]rune, 0, len(input))
+ for _, r := range input {
+ if r == '\n' || r == '\t' {
+ continue
+ }
+ if unicode.IsControl(r) {
+ continue
+ }
+ runes = append(runes, r)
+ }
+ return string(runes)
+}