Skip to content

Commit 2204278

Browse files
committed
fix: added bypass to database authentication if LDAP is not available
1 parent 555e3f8 commit 2204278

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

phpmyfaq/src/phpMyFAQ/User/CurrentUser.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,15 @@ public function login(string $login, #[SensitiveParameter] string $password): bo
162162
$login = strtok($login, '@\\');
163163
}
164164

165-
// Attempt to authenticate user by login and password
165+
// Attempt to authenticate a user by login and password
166166
$this->authContainer = $this->sortAuthContainer($this->authContainer);
167167
foreach ($this->authContainer as $authSource => $auth) {
168168
if ($auth->isValidLogin($login, $optData ?? []) === 0) {
169-
continue; // Login does not exist, try next auth method
169+
continue; // Login does not exist, try the next auth method
170170
}
171171

172172
if (!$auth->checkCredentials($login, $password, $optData ?? [])) {
173-
continue; // Incorrect password, try next auth method
173+
continue; // Incorrect password, try the next auth method
174174
}
175175

176176
// Login successful, proceed with post-login actions
@@ -231,7 +231,7 @@ public function isLoggedIn(): bool
231231
}
232232

233233
/**
234-
* Sets loggedIn to true if the 2FA-auth was successfully and saves the login to session.
234+
* Sets loggedIn to true if the 2FA-auth was successful and saves the login to session.
235235
*/
236236
public function twoFactorSuccess(): bool
237237
{
@@ -370,7 +370,7 @@ public function updateSessionId(bool $updateLastLogin = false): bool
370370

371371
$requestTime = Request::createFromGlobals()->server->get('REQUEST_TIME');
372372

373-
// save session information in user table
373+
// save session information in the user table
374374
$update = sprintf(
375375
"
376376
UPDATE
@@ -618,7 +618,7 @@ public function setSessionTimeout(int $timeout): void
618618
}
619619

620620
/**
621-
* Enables to remember me decision.
621+
* Enables to "remember me" decision.
622622
*/
623623
public function enableRememberMe(): void
624624
{

phpmyfaq/src/phpMyFAQ/User/UserAuthentication.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,17 @@ public function authenticate(string $username, #[SensitiveParameter] string $pas
9797
return $this->currentUser;
9898
}
9999

100-
/**
101-
* @throws UserException
102-
*/
103100
private function authenticateLdap(): void
104101
{
105102
if ($this->configuration->isLdapActive() && function_exists('ldap_connect')) {
106103
try {
107104
$authLdap = new AuthLdap($this->configuration);
108105
$this->currentUser->addAuth($authLdap, 'ldap');
109106
} catch (Exception $exception) {
110-
throw new UserException($exception->getMessage());
107+
// LDAP initialization failed - log error and continue with local auth fallback
108+
$this->configuration
109+
->getLogger()
110+
->error('LDAP authentication initialization failed: ' . $exception->getMessage());
111111
}
112112
}
113113
}

0 commit comments

Comments
 (0)