From 03fe2b3b812e68765b5df6cb27e7f352ebbc2f87 Mon Sep 17 00:00:00 2001
From: Roeland Jago Douma <roeland@famdouma.nl>
Date: Thu, 20 Dec 2018 11:09:10 +0100
Subject: Use a case insensitive search for email

Fixes #7084
Now entering wrongly cased email (roeland@ instead of Roeland@) for
password reset etc. Will also work.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
---
 lib/private/AllConfig.php    | 32 ++++++++++++++++++++++++++++++++
 lib/private/User/Manager.php |  2 +-
 2 files changed, 33 insertions(+), 1 deletion(-)

(limited to 'lib')

diff --git a/lib/private/AllConfig.php b/lib/private/AllConfig.php
index 58706e290fb..09520aae2a9 100644
--- a/lib/private/AllConfig.php
+++ b/lib/private/AllConfig.php
@@ -459,6 +459,38 @@ class AllConfig implements \OCP\IConfig {
 		return $userIDs;
 	}
 
+	/**
+	 * Determines the users that have the given value set for a specific app-key-pair
+	 *
+	 * @param string $appName the app to get the user for
+	 * @param string $key the key to get the user for
+	 * @param string $value the value to get the user for
+	 * @return array of user IDs
+	 */
+	public function getUsersForUserValueCaseInsensitive($appName, $key, $value) {
+		// TODO - FIXME
+		$this->fixDIInit();
+
+		$sql  = 'SELECT `userid` FROM `*PREFIX*preferences` ' .
+			'WHERE `appid` = ? AND `configkey` = ? ';
+
+		if($this->getSystemValue('dbtype', 'sqlite') === 'oci') {
+			//oracle hack: need to explicitly cast CLOB to CHAR for comparison
+			$sql .= 'AND LOWER(to_char(`configvalue`)) = LOWER(?)';
+		} else {
+			$sql .= 'AND LOWER(`configvalue`) = LOWER(?)';
+		}
+
+		$result = $this->connection->executeQuery($sql, array($appName, $key, $value));
+
+		$userIDs = array();
+		while ($row = $result->fetch()) {
+			$userIDs[] = $row['userid'];
+		}
+
+		return $userIDs;
+	}
+
 	public function getSystemConfig() {
 		return $this->systemConfig;
 	}
diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php
index 4243ced2e98..f1a2029a7d5 100644
--- a/lib/private/User/Manager.php
+++ b/lib/private/User/Manager.php
@@ -589,7 +589,7 @@ class Manager extends PublicEmitter implements IUserManager {
 	 * @since 9.1.0
 	 */
 	public function getByEmail($email) {
-		$userIds = $this->config->getUsersForUserValue('settings', 'email', $email);
+		$userIds = $this->config->getUsersForUserValueCaseInsensitive('settings', 'email', $email);
 
 		$users = array_map(function($uid) {
 			return $this->get($uid);
-- 
cgit v1.2.3