From 791a5ee7f4788542f78f32df956e30dd5be579fb Mon Sep 17 00:00:00 2001 From: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Date: Mon, 4 Dec 2017 09:40:36 +0000 Subject: [PATCH] Squash username to all lowercase letters upon registration (#361) * Squash username to all lowercase letters upon registration Signed-off-by: Andrew Morgan (https://amorgan.xyz) --- .../dendrite/clientapi/routing/register.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/register.go b/src/github.com/matrix-org/dendrite/clientapi/routing/register.go index ef8fbaf5..4b3c6c0c 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/register.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/register.go @@ -49,7 +49,7 @@ const ( var ( // TODO: Remove old sessions. Need to do so on a session-specific timeout. sessions = make(map[string][]authtypes.LoginType) // Sessions and completed flow stages - validUsernameRegex = regexp.MustCompile(`^[0-9a-zA-Z_\-./]+$`) + validUsernameRegex = regexp.MustCompile(`^[0-9a-z_\-./]+$`) ) // registerRequest represents the submitted registration request. @@ -183,6 +183,9 @@ func Register( } } + // Squash username to all lowercase letters + r.Username = strings.ToLower(r.Username) + if resErr = validateUserName(r.Username); resErr != nil { return *resErr } @@ -278,6 +281,10 @@ func LegacyRegister( if resErr != nil { return *resErr } + + // Squash username to all lowercase letters + r.Username = strings.ToLower(r.Username) + if resErr = validateUserName(r.Username); resErr != nil { return *resErr } @@ -478,6 +485,9 @@ func RegisterAvailable( ) util.JSONResponse { username := req.URL.Query().Get("username") + // Squash username to all lowercase letters + username = strings.ToLower(username) + if err := validateUserName(username); err != nil { return *err }