From a83ceb1791676b9d7e8659760be570895706ac2c Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 16 Dec 2012 13:12:57 +0100 Subject: c/user: register() prevent DB error if username is non-ascii The DB col is set to ascii_general_ci so if the username doesn't pass the charset check we shouldn't even bother query the db because that can trigger a collation error (utf-8 vs ascii). Signed-off-by: Florian Pritz --- application/controllers/user.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/application/controllers/user.php b/application/controllers/user.php index aa1ea235b..cac47ebe1 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -142,6 +142,10 @@ class User extends CI_Controller { if (!$username || strlen($username) > 32 || !preg_match("/^[a-z0-9]+$/", $username)) { $error[]= "Invalid username (only up to 32 chars of a-z0-9 are allowed)."; + } else { + if ($this->muser->username_exists($username)) { + $error[] = "Username already exists."; + } } $this->load->helper("email"); @@ -149,10 +153,6 @@ class User extends CI_Controller { $error[]= "Invalid email."; } - if ($this->muser->username_exists($username)) { - $error[] = "Username already exists."; - } - if (!$password || $password != $password_confirm) { $error[]= "No password or passwords don't match."; } -- cgit v1.2.3-24-g4f1b