Skip to content

Commit aef40c7

Browse files
authored
Merge pull request #27876 from nextcloud/bugfix/noid/use-cached-user-backend-info-for-password-login
2 parents 7e3b6e7 + 1b8ebf2 commit aef40c7

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/private/User/Manager.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,13 @@ public function checkPasswordNoLogging($loginName, $password) {
246246
$loginName = str_replace("\0", '', $loginName);
247247
$password = str_replace("\0", '', $password);
248248

249-
foreach ($this->backends as $backend) {
249+
$cachedBackend = $this->cache->get($loginName);
250+
if ($cachedBackend !== null && isset($this->backends[$cachedBackend])) {
251+
$backends = [$this->backends[$cachedBackend]];
252+
} else {
253+
$backends = $this->backends;
254+
}
255+
foreach ($backends as $backend) {
250256
if ($backend->implementsActions(Backend::CHECK_PASSWORD)) {
251257
$uid = $backend->checkPassword($loginName, $password);
252258
if ($uid !== false) {
@@ -257,10 +263,10 @@ public function checkPasswordNoLogging($loginName, $password) {
257263

258264
// since http basic auth doesn't provide a standard way of handling non ascii password we allow password to be urlencoded
259265
// we only do this decoding after using the plain password fails to maintain compatibility with any password that happens
260-
// to contains urlencoded patterns by "accident".
266+
// to contain urlencoded patterns by "accident".
261267
$password = urldecode($password);
262268

263-
foreach ($this->backends as $backend) {
269+
foreach ($backends as $backend) {
264270
if ($backend->implementsActions(Backend::CHECK_PASSWORD)) {
265271
$uid = $backend->checkPassword($loginName, $password);
266272
if ($uid !== false) {

0 commit comments

Comments
 (0)