ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilAuthProviderDatabase.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  private bool $verify_password = true;
24 
25  public function withoutPasswordVerification(): self
26  {
27  $clone = clone $this;
28  $clone->verify_password = false;
29 
30  return $clone;
31  }
32 
33  public function doAuthentication(ilAuthStatus $status): bool
34  {
36  $user = ilObjectFactory::getInstanceByObjId(ilObjUser::_loginExists($this->getCredentials()->getUsername()), false);
37 
38  $this->getLogger()->debug('Trying to authenticate user: ' . $this->getCredentials()->getUsername());
39  if ($user instanceof ilObjUser) {
40  if ($user->getId() === ANONYMOUS_USER_ID) {
41  $this->getLogger()->notice('Failed authentication for anonymous user id. ');
42  $this->handleAuthenticationFail($status, 'err_wrong_login');
43 
44  return false;
45  }
46 
47  if (!ilAuthUtils::isLocalPasswordEnabledForAuthMode($user->getAuthMode(true))) {
48  $this->getLogger()->debug('DB authentication failed: current user auth mode does not allow local validation.');
49  $this->getLogger()->debug('User auth mode: ' . $user->getAuthMode(true));
50  $this->handleAuthenticationFail($status, 'err_wrong_login');
51 
52  return false;
53  }
54 
55  if (!$this->verify_password || ilUserPasswordManager::getInstance()->verifyPassword($user, $this->getCredentials()->getPassword())) {
56  $this->getLogger()->debug('Successfully authenticated user: ' . $this->getCredentials()->getUsername());
58  $status->setAuthenticatedUserId($user->getId());
59 
60  return true;
61  }
62  }
63 
64  $this->handleAuthenticationFail($status, 'err_wrong_login');
65 
66  return false;
67  }
68 }
const ANONYMOUS_USER_ID
Definition: constants.php:27
handleAuthenticationFail(ilAuthStatus $status, string $a_reason)
Handle failed authentication.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setStatus(int $a_status)
Set auth status.
static _loginExists(string $a_login, int $a_user_id=0)
check if a login name already exists You may exclude a user from the check by giving his user id as 2...
getLogger()
Get logger.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static isLocalPasswordEnabledForAuthMode($a_authmode)
Check if local password validation is enabled for a specific auth_mode.
setAuthenticatedUserId(int $a_id)
doAuthentication(\ilAuthStatus $status)
Do authentication.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance()
Singleton method to reduce footprint (included files, created instances)