]> source.dussan.org Git - nextcloud-server.git/commitdiff
perf: Use more performant way to obtain and check the email as a login name with...
authorJulius Härtl <jus@bitgrid.net>
Thu, 30 Nov 2023 10:46:54 +0000 (11:46 +0100)
committerJulius Härtl <jus@bitgrid.net>
Thu, 30 Nov 2023 19:51:47 +0000 (20:51 +0100)
Signed-off-by: Julius Härtl <jus@bitgrid.net>
lib/private/User/Session.php
tests/lib/User/SessionTest.php

index f3282009a4dfe8b265dac8e828aad46f68604ce4..5689de3995f76a9819a33024dd4f675d0b9a545b 100644 (file)
@@ -456,8 +456,17 @@ class Session implements IUserSession, Emitter {
                                $this->handleLoginFailed($throttler, $currentDelay, $remoteAddress, $user, $password);
                                return false;
                        }
-                       $users = $this->manager->getByEmail($user);
-                       if (!(\count($users) === 1 && $this->login($users[0]->getUID(), $password))) {
+
+                       if ($isTokenPassword) {
+                               $dbToken = $this->tokenProvider->getToken($password);
+                               $userFromToken = $this->manager->get($dbToken->getUID());
+                               $isValidEmailLogin = $userFromToken->getEMailAddress() === $user;
+                       } else {
+                               $users = $this->manager->getByEmail($user);
+                               $isValidEmailLogin = (\count($users) === 1 && $this->login($users[0]->getUID(), $password));
+                       }
+
+                       if (!$isValidEmailLogin) {
                                $this->handleLoginFailed($throttler, $currentDelay, $remoteAddress, $user, $password);
                                return false;
                        }
index d6db17d9d45cd0e466b2bb0a8b865cf2d07bce9d..3b8d75f694c0593223301af22deecf782845cb69 100644 (file)
@@ -1110,7 +1110,7 @@ class SessionTest extends \Test\TestCase {
 
                $userSession->expects($this->once())
                        ->method('isTokenPassword')
-                       ->willReturn(true);
+                       ->willReturn(false);
                $userSession->expects($this->once())
                        ->method('login')
                        ->with('john@foo.bar', 'I-AM-AN-PASSWORD')