diff --git a/server/public/model/user.go b/server/public/model/user.go index b01e667c5d8..4bbe1808d3e 100644 --- a/server/public/model/user.go +++ b/server/public/model/user.go @@ -976,8 +976,7 @@ func HashPassword(password string) (string, error) { } var validUsernameChars = regexp.MustCompile(`^[a-z0-9\.\-_]+$`) -var validUsername = regexp.MustCompile(`^[a-z][a-z0-9\.\-_]*$`) -var validUsernameCharsForRemote = regexp.MustCompile(`^[a-z][a-z0-9\.\-_:]*$`) +var validUsernameCharsForRemote = regexp.MustCompile(`^[a-z0-9\.\-_:]*$`) var restrictedUsernames = map[string]struct{}{ "all": {}, @@ -991,7 +990,7 @@ func IsValidUsername(s string) bool { return false } - if !validUsername.MatchString(s) { + if !validUsernameChars.MatchString(s) { return false } diff --git a/server/public/model/user_test.go b/server/public/model/user_test.go index 927b8f22424..b870a7018c0 100644 --- a/server/public/model/user_test.go +++ b/server/public/model/user_test.go @@ -431,9 +431,9 @@ var usernames = []usernamesTest{ {"spin-punch", true, true}, {"sp", true, true}, {"s", true, true}, - {"1spin-punch", false, false}, - {"-spin-punch", false, false}, - {".spin-punch", false, false}, + {"1spin-punch", true, true}, + {"-spin-punch", true, true}, + {".spin-punch", true, true}, {"Spin-punch", false, false}, {"spin punch-", false, false}, {"spin_punch", true, true},