ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAuthProviderDatabase.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24{
25 private bool $verify_password = true;
26
27 public function withoutPasswordVerification(): self
28 {
29 $clone = clone $this;
30 $clone->verify_password = false;
31
32 return $clone;
33 }
34
35 public function doAuthentication(ilAuthStatus $status): bool
36 {
38 $user = ilObjectFactory::getInstanceByObjId(ilObjUser::_loginExists($this->getCredentials()->getUsername()), false);
39
40 $this->getLogger()->debug('Trying to authenticate user: ' . $this->getCredentials()->getUsername());
41 if ($user instanceof ilObjUser) {
42 if ($user->getId() === ANONYMOUS_USER_ID) {
43 $this->getLogger()->notice('Failed authentication for anonymous user id. ');
44 $this->handleAuthenticationFail($status, 'err_wrong_login');
45
46 return false;
47 }
48
49 if (!ilAuthUtils::isLocalPasswordEnabledForAuthMode($user->getAuthMode(true))) {
50 $this->getLogger()->debug('DB authentication failed: current user auth mode does not allow local validation.');
51 $this->getLogger()->debug('User auth mode: ' . $user->getAuthMode(true));
52 $this->handleAuthenticationFail($status, 'err_wrong_login');
53
54 return false;
55 }
56
57 if (!$this->verify_password || LocalUserPasswordManager::getInstance()->verifyPassword($user, $this->getCredentials()->getPassword())) {
58 $this->getLogger()->debug('Successfully authenticated user: ' . $this->getCredentials()->getUsername());
60 $status->setAuthenticatedUserId($user->getId());
61
62 return true;
63 }
64 }
65
66 $this->handleAuthenticationFail($status, 'err_wrong_login');
67
68 return false;
69 }
70}
handleAuthenticationFail(ilAuthStatus $status, string $a_reason)
setAuthenticatedUserId(int $a_id)
setStatus(int $a_status)
Set auth status.
const int STATUS_AUTHENTICATED
static isLocalPasswordEnabledForAuthMode($a_authmode)
Check if local password validation is enabled for a specific auth_mode.
User class.
static _loginExists(string $a_login, int $a_user_id=0)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
const ANONYMOUS_USER_ID
Definition: constants.php:27
doAuthentication(ilAuthStatus $status)