From 5e64d43732434f9979eb40c184dd8bc454dfcc26 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Wed, 18 Sep 2013 07:33:57 +0200 Subject: [PATCH] [IMPROVEMENT] Allow user login via E-Mail --- public/include/classes/user.class.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/public/include/classes/user.class.php b/public/include/classes/user.class.php index 62ff987a..3db25611 100644 --- a/public/include/classes/user.class.php +++ b/public/include/classes/user.class.php @@ -43,6 +43,9 @@ class User { public function getUserName($id) { return $this->getSingle($id, 'username', 'id'); } + public function getUserNameByEmail($email) { + return $this->getSingle($email, 'username', 'email', 's'); + } public function getUserId($username) { return $this->getSingle($username, 'id', 'username', 's'); } @@ -126,6 +129,13 @@ class User { $this->setErrorMessage("Invalid username or password."); return false; } + if (filter_var($username, FILTER_VALIDATE_EMAIL)) { + $this->debug->append("Username is an e-mail", 2); + if (!$username = $this->getUserNameByEmail($username)) { + $this->setErrorMessage("Invalid username or password."); + return false; + } + } if ($this->isLocked($this->getUserId($username))) { $this->setErrorMessage("Account is locked. Please contact site support."); return false;