ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilUserPasswordManager Class Reference
+ Collaboration diagram for ilUserPasswordManager:

Public Member Functions

 __construct (array $config=[])
 Please use the singleton method for instance creation The constructor is still public because of the unit tests. More...
 
 setSettings (?ilSetting $settings)
 
 setDb (ilDBInterface $db)
 
 getEncoderName ()
 
 setEncoderName (string $encoderName)
 
 getEncoderFactory ()
 
 setEncoderFactory (ilUserPasswordEncoderFactory $encoderFactory)
 
 encodePassword (ilObjUser $user, string $raw)
 
 isEncodingTypeSupported (string $name)
 
 verifyPassword (ilObjUser $user, string $raw)
 
 resetLastPasswordChangeForLocalUsers ()
 

Static Public Member Functions

static getInstance ()
 Singleton method to reduce footprint (included files, created instances) More...
 

Protected Attributes

ilUserPasswordEncoderFactory $encoderFactory = null
 
ilSetting $settings = null
 
ilDBInterface $db = null
 
string $encoderName = null
 
array $config = []
 

Private Attributes

const MIN_SALT_SIZE = 16
 

Static Private Attributes

static self $instance = null
 

Detailed Description

Definition at line 26 of file class.ilUserPasswordManager.php.

Constructor & Destructor Documentation

◆ __construct()

ilUserPasswordManager::__construct ( array  $config = [])

Please use the singleton method for instance creation The constructor is still public because of the unit tests.

Parameters
array<string,mixed>$config
Exceptions
ilUserException
JsonException

Definition at line 48 of file class.ilUserPasswordManager.php.

References ILIAS\LTI\ToolProvider\$key, getEncoderFactory(), getEncoderName(), setDb(), setEncoderFactory(), setEncoderName(), and setSettings().

49  {
50  if (!empty($config)) {
51  foreach ($config as $key => $value) {
52  switch (strtolower($key)) {
53  case 'settings':
54  $this->setSettings($value);
55  break;
56  case 'db':
57  $this->setDb($value);
58  break;
59  case 'password_encoder':
60  $this->setEncoderName($value);
61  break;
62  case 'encoder_factory':
63  $this->setEncoderFactory($value);
64  break;
65  }
66  }
67  }
68 
69  if (!$this->getEncoderName()) {
70  throw new ilUserException(sprintf(
71  '"password_encoder" must be set in %s.',
72  json_encode($config, JSON_THROW_ON_ERROR)
73  ));
74  }
75 
76  if (!($this->getEncoderFactory() instanceof ilUserPasswordEncoderFactory)) {
77  throw new ilUserException(sprintf(
78  '"encoder_factory" must be instance of ilUserPasswordEncoderFactory and set in %s.',
79  json_encode($config, JSON_THROW_ON_ERROR)
80  ));
81  }
82  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $key
Consumer key/client ID value.
Definition: System.php:193
setEncoderFactory(ilUserPasswordEncoderFactory $encoderFactory)
+ Here is the call graph for this function:

Member Function Documentation

◆ encodePassword()

ilUserPasswordManager::encodePassword ( ilObjUser  $user,
string  $raw 
)

Definition at line 147 of file class.ilUserPasswordManager.php.

References ilPasswordUtils\getBytes(), getEncoderFactory(), getEncoderName(), ilObjUser\getPasswordSalt(), ilObjUser\PASSWD_CRYPTED, ilObjUser\setPasswd(), ilObjUser\setPasswordEncodingType(), and ilObjUser\setPasswordSalt().

147  : void
148  {
149  $encoder = $this->getEncoderFactory()->getEncoderByName($this->getEncoderName());
150  $user->setPasswordEncodingType($encoder->getName());
151  if ($encoder->requiresSalt()) {
152  $user->setPasswordSalt(
153  substr(str_replace('+', '.', base64_encode(ilPasswordUtils::getBytes(self::MIN_SALT_SIZE))), 0, 22)
154  );
155  } else {
156  $user->setPasswordSalt(null);
157  }
158  $user->setPasswd($encoder->encodePassword($raw, (string) $user->getPasswordSalt()), ilObjUser::PASSWD_CRYPTED);
159  }
setPasswordSalt(?string $password_salt)
setPasswd(string $a_str, string $a_type=ilObjUser::PASSWD_PLAIN)
static getBytes(int $length)
Generate random bytes using OpenSSL or Mcrypt and mt_rand() as fallback.
const PASSWD_CRYPTED
setPasswordEncodingType(?string $password_encryption_type)
+ Here is the call graph for this function:

◆ getEncoderFactory()

ilUserPasswordManager::getEncoderFactory ( )

Definition at line 137 of file class.ilUserPasswordManager.php.

References $encoderFactory.

Referenced by __construct(), encodePassword(), isEncodingTypeSupported(), and verifyPassword().

+ Here is the caller graph for this function:

◆ getEncoderName()

ilUserPasswordManager::getEncoderName ( )

Definition at line 127 of file class.ilUserPasswordManager.php.

References $encoderName.

Referenced by __construct(), encodePassword(), and verifyPassword().

127  : ?string
128  {
129  return $this->encoderName;
130  }
+ Here is the caller graph for this function:

◆ getInstance()

static ilUserPasswordManager::getInstance ( )
static

Singleton method to reduce footprint (included files, created instances)

Returns
self
Exceptions
ilUserException
ilPasswordException

Definition at line 90 of file class.ilUserPasswordManager.php.

References $DIC, and ilFileUtils\getDataDir().

Referenced by ilPDNewsBlockGUI\changeFeedSettings(), ilObjUserFolderGUI\forceUserPasswordResetObject(), ilObjUser\isPasswordChangeDemanded(), ilObjUser\resetPassword(), ilObjUser\saveAsNew(), ilPersonalSettingsGUI\savePassword(), and ilObjUser\update().

90  : self
91  {
92  global $DIC;
93 
94  if (self::$instance instanceof self) {
95  return self::$instance;
96  }
97 
98  $password_manager = new ilUserPasswordManager(
99  [
100  'encoder_factory' => new ilUserPasswordEncoderFactory(
101  [
102  'default_password_encoder' => 'bcryptphp',
103  'ignore_security_flaw' => true,
104  'data_directory' => ilFileUtils::getDataDir()
105  ]
106  ),
107  'password_encoder' => 'bcryptphp',
108  'settings' => $DIC->isDependencyAvailable('settings') ? $DIC->settings() : null,
109  'db' => $DIC->database(),
110  ]
111  );
112 
113  self::$instance = $password_manager;
114  return self::$instance;
115  }
global $DIC
Definition: feed.php:28
static getDataDir()
get data directory (outside webspace)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isEncodingTypeSupported()

ilUserPasswordManager::isEncodingTypeSupported ( string  $name)

Definition at line 161 of file class.ilUserPasswordManager.php.

References getEncoderFactory().

161  : bool
162  {
163  return in_array($name, $this->getEncoderFactory()->getSupportedEncoderNames());
164  }
if($format !==null) $name
Definition: metadata.php:247
+ Here is the call graph for this function:

◆ resetLastPasswordChangeForLocalUsers()

ilUserPasswordManager::resetLastPasswordChangeForLocalUsers ( )

Definition at line 185 of file class.ilUserPasswordManager.php.

References ilAuthUtils\AUTH_LOCAL, and ILIAS\Repository\settings().

185  : void
186  {
187  $defaultAuthMode = $this->settings->get('auth_mode');
188  $defaultAuthModeCondition = '';
189  if ((int) $defaultAuthMode === ilAuthUtils::AUTH_LOCAL) {
190  $defaultAuthModeCondition = ' OR auth_mode = ' . $this->db->quote('default', 'text');
191  }
192 
193  $this->db->manipulateF(
194  "UPDATE usr_data SET passwd_policy_reset = %s WHERE (auth_mode = %s $defaultAuthModeCondition)",
195  ['integer', 'text'],
196  [1, 'local']
197  );
198  }
+ Here is the call graph for this function:

◆ setDb()

ilUserPasswordManager::setDb ( ilDBInterface  $db)

Definition at line 122 of file class.ilUserPasswordManager.php.

References $db.

Referenced by __construct().

122  : void
123  {
124  $this->db = $db;
125  }
+ Here is the caller graph for this function:

◆ setEncoderFactory()

ilUserPasswordManager::setEncoderFactory ( ilUserPasswordEncoderFactory  $encoderFactory)

Definition at line 142 of file class.ilUserPasswordManager.php.

References $encoderFactory.

Referenced by __construct().

142  : void
143  {
144  $this->encoderFactory = $encoderFactory;
145  }
ilUserPasswordEncoderFactory $encoderFactory
+ Here is the caller graph for this function:

◆ setEncoderName()

ilUserPasswordManager::setEncoderName ( string  $encoderName)

Definition at line 132 of file class.ilUserPasswordManager.php.

References $encoderName.

Referenced by __construct().

132  : void
133  {
134  $this->encoderName = $encoderName;
135  }
+ Here is the caller graph for this function:

◆ setSettings()

ilUserPasswordManager::setSettings ( ?ilSetting  $settings)

Definition at line 117 of file class.ilUserPasswordManager.php.

References $settings, and ILIAS\Repository\settings().

Referenced by __construct().

117  : void
118  {
119  $this->settings = $settings;
120  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ verifyPassword()

ilUserPasswordManager::verifyPassword ( ilObjUser  $user,
string  $raw 
)

Definition at line 166 of file class.ilUserPasswordManager.php.

References getEncoderFactory(), getEncoderName(), ilObjUser\getPasswd(), ilObjUser\getPasswordEncodingType(), ilObjUser\getPasswordSalt(), and ilObjUser\resetPassword().

166  : bool
167  {
168  $encoder = $this->getEncoderFactory()->getEncoderByName($user->getPasswordEncodingType(), true);
169  if ($this->getEncoderName() !== $encoder->getName()) {
170  if ($encoder->isPasswordValid($user->getPasswd(), $raw, (string) $user->getPasswordSalt())) {
171  $user->resetPassword($raw, $raw);
172  return true;
173  }
174  } elseif ($encoder->isPasswordValid($user->getPasswd(), $raw, (string) $user->getPasswordSalt())) {
175  if ($encoder->requiresReencoding($user->getPasswd())) {
176  $user->resetPassword($raw, $raw);
177  }
178 
179  return true;
180  }
181 
182  return false;
183  }
resetPassword(string $raw, string $raw_retype)
Resets the user password.
+ Here is the call graph for this function:

Field Documentation

◆ $config

array ilUserPasswordManager::$config = []
protected

Definition at line 39 of file class.ilUserPasswordManager.php.

◆ $db

ilDBInterface ilUserPasswordManager::$db = null
protected

Definition at line 34 of file class.ilUserPasswordManager.php.

Referenced by setDb().

◆ $encoderFactory

ilUserPasswordEncoderFactory ilUserPasswordManager::$encoderFactory = null
protected

Definition at line 32 of file class.ilUserPasswordManager.php.

Referenced by getEncoderFactory(), and setEncoderFactory().

◆ $encoderName

string ilUserPasswordManager::$encoderName = null
protected

Definition at line 35 of file class.ilUserPasswordManager.php.

Referenced by getEncoderName(), and setEncoderName().

◆ $instance

self ilUserPasswordManager::$instance = null
staticprivate

Definition at line 30 of file class.ilUserPasswordManager.php.

◆ $settings

ilSetting ilUserPasswordManager::$settings = null
protected

Definition at line 33 of file class.ilUserPasswordManager.php.

Referenced by setSettings().

◆ MIN_SALT_SIZE

const ilUserPasswordManager::MIN_SALT_SIZE = 16
private

Definition at line 28 of file class.ilUserPasswordManager.php.


The documentation for this class was generated from the following file: