auth-ui: rewrite ui
Change-Id: I6f00867015ec77aa7e336e89da4dc1b081e330c6
diff --git a/core/auth/ui/validation.go b/core/auth/ui/validation.go
new file mode 100644
index 0000000..2e861d5
--- /dev/null
+++ b/core/auth/ui/validation.go
@@ -0,0 +1,47 @@
+package main
+
+import (
+ "strings"
+ "unicode"
+)
+
+type ValidationError struct {
+ Field string `json:"field"`
+ Message string `json:"message"`
+}
+
+func validateUsername(username string) []ValidationError {
+ var errors []ValidationError
+ if len(username) < 3 {
+ errors = append(errors, ValidationError{"username", "Username must be at least 3 characters long."})
+ }
+ // TODO other validations
+ return errors
+}
+
+func validatePassword(password string) []ValidationError {
+ var errors []ValidationError
+ if len(password) < 20 {
+ errors = append(errors, ValidationError{"password", "Password must be at least 20 characters long."})
+ }
+ digit := false
+ lowerCase := false
+ upperCase := false
+ special := false
+ for _, c := range password {
+ if unicode.IsDigit(c) {
+ digit = true
+ } else if unicode.IsLower(c) {
+ lowerCase = true
+ } else if unicode.IsUpper(c) {
+ upperCase = true
+ } else if strings.Contains(" !\"#$%&'()*+,-./:;<=>?@[\\]^_{|}~", string(c)) {
+ special = true
+ }
+ }
+ if !digit || !lowerCase || !upperCase || !special {
+ errors = append(errors, ValidationError{"password", "Password must contain at least one digit, lower&upper case and special characters"})
+ }
+ // TODO other validations
+ return errors
+}