ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 ()
 Single method to reduce footprint (included files, created instances) More...
 

Data Fields

const MIN_SALT_SIZE = 16
 

Protected Attributes

 $encoderFactory
 
 $encoderName
 
 $config = []
 
 $settings
 
 $db
 

Static Private Attributes

static $instance
 

Detailed Description

Definition at line 9 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$config
Exceptions
ilUserException

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

39 {
40 if (!empty($config)) {
41 foreach ($config as $key => $value) {
42 switch (strtolower($key)) {
43 case 'settings':
44 $this->setSettings($value);
45 break;
46 case 'db':
47 $this->setDb($value);
48 break;
49 case 'password_encoder':
50 $this->setEncoderName($value);
51 break;
52 case 'encoder_factory':
53 $this->setEncoderFactory($value);
54 break;
55 }
56 }
57 }
58
59 if (!$this->getEncoderName()) {
60 throw new ilUserException(sprintf('"password_encoder" must be set in %s.', json_encode($config)));
61 }
62
63 if (!($this->getEncoderFactory() instanceof ilUserPasswordEncoderFactory)) {
64 throw new ilUserException(sprintf(
65 '"encoder_factory" must be instance of ilUserPasswordEncoderFactory and set in %s.',
66 json_encode($config)
67 ));
68 }
69 }
Class for user related exception handling in ILIAS.
setEncoderFactory(ilUserPasswordEncoderFactory $encoderFactory)

References $config, getEncoderFactory(), getEncoderName(), setDb(), setEncoderFactory(), setEncoderName(), and setSettings().

+ Here is the call graph for this function:

Member Function Documentation

◆ encodePassword()

ilUserPasswordManager::encodePassword ( ilObjUser  $user,
string  $raw 
)
Parameters
ilObjUser$user
string$rawThe raw password
Exceptions
ilUserException

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

157 : void
158 {
159 $encoder = $this->getEncoderFactory()->getEncoderByName($this->getEncoderName());
160 $user->setPasswordEncodingType($encoder->getName());
161 if ($encoder->requiresSalt()) {
162 $user->setPasswordSalt(
163 substr(str_replace('+', '.', base64_encode(ilPasswordUtils::getBytes(self::MIN_SALT_SIZE))), 0, 22)
164 );
165 } else {
166 $user->setPasswordSalt(null);
167 }
168 $user->setPasswd($encoder->encodePassword($raw, (string) $user->getPasswordSalt()), IL_PASSWD_CRYPTED);
169 }
const IL_PASSWD_CRYPTED
setPasswordEncodingType($password_encryption_type)
setPasswd($a_str, $a_type=IL_PASSWD_PLAIN)
set password @access public
setPasswordSalt($password_salt)
static getBytes($length)
Generate random bytes using OpenSSL or Mcrypt and mt_rand() as fallback.

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

+ Here is the call graph for this function:

◆ getEncoderFactory()

ilUserPasswordManager::getEncoderFactory ( )
Returns
ilUserPasswordEncoderFactory|null

Definition at line 139 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 ( )
Returns
string|null

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

123 : ?string
124 {
125 return $this->encoderName;
126 }

References $encoderName.

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

+ Here is the caller graph for this function:

◆ getInstance()

static ilUserPasswordManager::getInstance ( )
static

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

Returns
self
Exceptions
ilUserException
ilPasswordException

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

77 : self
78 {
79 global $DIC;
80
81 if (self::$instance instanceof self) {
82 return self::$instance;
83 }
84
85 $password_manager = new ilUserPasswordManager(
86 [
87 'encoder_factory' => new ilUserPasswordEncoderFactory(
88 [
89 'default_password_encoder' => 'bcryptphp',
90 'ignore_security_flaw' => true,
91 'data_directory' => ilUtil::getDataDir()
92 ]
93 ),
94 'password_encoder' => 'bcryptphp',
95 'settings' => $DIC->isDependencyAvailable('settings') ? $DIC->settings() : null,
96 'db' => $DIC->database(),
97 ]
98 );
99
100 self::$instance = $password_manager;
101 return self::$instance;
102 }
static getDataDir()
get data directory (outside webspace)
$DIC
Definition: xapitoken.php:46

References $DIC, $instance, and ilUtil\getDataDir().

Referenced by ilPDNewsBlockGUI\changeFeedSettings(), ilObjUserFolderGUI\forceUserPasswordResetObject(), ilObjUser\isPasswordChangeDemanded(), ilSetup\loginAsClient(), and ilPersonalSettingsGUI\savePassword().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isEncodingTypeSupported()

ilUserPasswordManager::isEncodingTypeSupported ( string  $name)
Parameters
string$name
Returns
bool

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

175 : bool
176 {
177 return in_array($name, $this->getEncoderFactory()->getSupportedEncoderNames());
178 }
if($format !==null) $name
Definition: metadata.php:230

References $name, and getEncoderFactory().

+ Here is the call graph for this function:

◆ resetLastPasswordChangeForLocalUsers()

ilUserPasswordManager::resetLastPasswordChangeForLocalUsers ( )

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

208 : void
209 {
210 $defaultAuthMode = $this->settings->get('auth_mode');
211 $defaultAuthModeCondition = '';
212 if ((int) $defaultAuthMode === (int) AUTH_LOCAL) {
213 $defaultAuthModeCondition = ' OR auth_mode = ' . $this->db->quote('default', 'text');
214 }
215
216 $this->db->manipulateF(
217 "
218 UPDATE usr_data
219 SET passwd_policy_reset = %s
220 WHERE (auth_mode = %s $defaultAuthModeCondition)",
221 ['integer', 'text'],
222 [1, 'local']
223 );
224 }
const AUTH_LOCAL
settings()
Definition: settings.php:2

References AUTH_LOCAL, and settings().

+ Here is the call graph for this function:

◆ setDb()

ilUserPasswordManager::setDb ( ilDBInterface  $db)
Parameters
ilDBInterface$db

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

115 : void
116 {
117 $this->db = $db;
118 }

References $db.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setEncoderFactory()

ilUserPasswordManager::setEncoderFactory ( ilUserPasswordEncoderFactory  $encoderFactory)
Parameters
ilUserPasswordEncoderFactory$encoderFactory

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

147 : void
148 {
149 $this->encoderFactory = $encoderFactory;
150 }

References $encoderFactory.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setEncoderName()

ilUserPasswordManager::setEncoderName ( string  $encoderName)
Parameters
string$encoderName

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

131 : void
132 {
133 $this->encoderName = $encoderName;
134 }

References $encoderName.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setSettings()

ilUserPasswordManager::setSettings ( ?ilSetting  $settings)
Parameters
ilSetting | null$settings

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

107 : void
108 {
109 $this->settings = $settings;
110 }

References $settings, and settings().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ verifyPassword()

ilUserPasswordManager::verifyPassword ( ilObjUser  $user,
string  $raw 
)
Parameters
ilObjUser$user
string$raw
Returns
bool
Exceptions
ilUserException

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

186 : bool
187 {
188 $encoder = $this->getEncoderFactory()->getEncoderByName($user->getPasswordEncodingType(), true);
189 if ($this->getEncoderName() != $encoder->getName()) {
190 if ($encoder->isPasswordValid((string) $user->getPasswd(), $raw, (string) $user->getPasswordSalt())) {
191 $user->resetPassword($raw, $raw);
192 return true;
193 }
194 } elseif ($encoder->isPasswordValid((string) $user->getPasswd(), $raw, (string) $user->getPasswordSalt())) {
195 if ($encoder->requiresReencoding((string) $user->getPasswd())) {
196 $user->resetPassword($raw, $raw);
197 }
198
199 return true;
200 }
201
202 return false;
203 }
getPasswd()
get password

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

+ Here is the call graph for this function:

Field Documentation

◆ $config

ilUserPasswordManager::$config = []
protected

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

Referenced by __construct().

◆ $db

ilUserPasswordManager::$db
protected

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

Referenced by setDb().

◆ $encoderFactory

ilUserPasswordManager::$encoderFactory
protected

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

Referenced by getEncoderFactory(), and setEncoderFactory().

◆ $encoderName

ilUserPasswordManager::$encoderName
protected

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

Referenced by getEncoderName(), and setEncoderName().

◆ $instance

ilUserPasswordManager::$instance
staticprivate

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

Referenced by getInstance().

◆ $settings

ilUserPasswordManager::$settings
protected

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

Referenced by setSettings().

◆ MIN_SALT_SIZE

const ilUserPasswordManager::MIN_SALT_SIZE = 16

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


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