ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilSetupPasswordManager Class Reference

Class ilSetupPasswordManager. More...

+ Collaboration diagram for ilSetupPasswordManager:

Public Member Functions

 __construct (array $config=[])
 ilSetupPasswordManager constructor. More...
 
 getEncoderFactory ()
 
 setEncoderFactory (\ilSetupPasswordEncoderFactory $encoderFactory)
 
 getEncoderName ()
 
 setEncoderName (string $encoderName)
 
 encodePassword (string $raw)
 Encodes the raw password based on the relevant encoding strategy. More...
 
 verifyPassword (string $encoded, string $raw, callable $passwordReHashCallback)
 Verifies if the passed raw password matches the encoded one, based on the current encoding strategy. More...
 

Private Attributes

 $encoderName
 
 $encoderFactory
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

ilSetupPasswordManager constructor.

Parameters
array$config
Exceptions
Exception

Definition at line 25 of file class.ilSetupPasswordManager.php.

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

26  {
27  if (!empty($config)) {
28  foreach ($config as $key => $value) {
29  switch (strtolower($key)) {
30  case 'password_encoder':
31  $this->setEncoderName($value);
32  break;
33 
34  case 'encoder_factory':
35  $this->setEncoderFactory($value);
36  break;
37  }
38  }
39  }
40 
41  if (!$this->getEncoderName()) {
42  throw new \Exception(sprintf('"password_encoder" must be set in %s.', json_encode($config)));
43  }
44 
45  if (!($this->getEncoderFactory() instanceof \ilSetupPasswordEncoderFactory)) {
46  throw new \ilUserException(sprintf('"encoder_factory" must be instance of \ilSetupPasswordEncoderFactory and set in %s.', json_encode($config)));
47  }
48  }
$config
Definition: bootstrap.php:15
setEncoderFactory(\ilSetupPasswordEncoderFactory $encoderFactory)
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

Member Function Documentation

◆ encodePassword()

ilSetupPasswordManager::encodePassword ( string  $raw)

Encodes the raw password based on the relevant encoding strategy.

Parameters
string$raw
Returns
string
Exceptions

Definition at line 88 of file class.ilSetupPasswordManager.php.

References getEncoderFactory(), and getEncoderName().

88  : string
89  {
90  $encoder = $this->getEncoderFactory()->getEncoderByName($this->getEncoderName());
91 
92  return $encoder->encodePassword($raw, '');
93  }
+ Here is the call graph for this function:

◆ getEncoderFactory()

ilSetupPasswordManager::getEncoderFactory ( )
Returns

Definition at line 53 of file class.ilSetupPasswordManager.php.

References $encoderFactory.

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

+ Here is the caller graph for this function:

◆ getEncoderName()

ilSetupPasswordManager::getEncoderName ( )
Returns
string

Definition at line 69 of file class.ilSetupPasswordManager.php.

References $encoderName.

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

69  : string
70  {
71  return $this->encoderName;
72  }
+ Here is the caller graph for this function:

◆ setEncoderFactory()

ilSetupPasswordManager::setEncoderFactory ( \ilSetupPasswordEncoderFactory  $encoderFactory)
Parameters
\ilSetupPasswordEncoderFactory$encoderFactory

Definition at line 61 of file class.ilSetupPasswordManager.php.

References $encoderFactory.

Referenced by __construct().

62  {
63  $this->encoderFactory = $encoderFactory;
64  }
+ Here is the caller graph for this function:

◆ setEncoderName()

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

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

References $encoderName.

Referenced by __construct().

78  {
79  $this->encoderName = $encoderName;
80  }
+ Here is the caller graph for this function:

◆ verifyPassword()

ilSetupPasswordManager::verifyPassword ( string  $encoded,
string  $raw,
callable  $passwordReHashCallback 
)

Verifies if the passed raw password matches the encoded one, based on the current encoding strategy.

Parameters
string$encoded
string$raw
callable$passwordReHashCallbackA callback passed by consumer, which accepts the raw password and is called if the encoder strategy decides a password has to be re-hashed.
Returns
bool
Exceptions

Definition at line 104 of file class.ilSetupPasswordManager.php.

References getEncoderFactory(), and getEncoderName().

104  : bool
105  {
106  $currentEncoder = $this->getEncoderFactory()->getFirstEncoderForEncodedPasswordAndMatchers(
107  $encoded,
108  [
109  'md5' => function ($encoded) {
110  return is_string($encoded) && strlen($encoded) === 32;
111  },
112  'bcryptphp' => function ($encoded) {
113  return is_string($encoded) && substr($encoded, 0, 4) === '$2y$' && strlen($encoded) === 60;
114  }
115  ]
116  );
117 
118  if ($this->getEncoderName() != $currentEncoder->getName()) {
119  if ($currentEncoder->isPasswordValid($encoded, $raw, '')) {
120  $passwordReHashCallback($raw);
121  return true;
122  }
123  } elseif ($currentEncoder->isPasswordValid($encoded, $raw, '')) {
124  if ($currentEncoder->requiresReencoding($encoded)) {
125  $passwordReHashCallback($raw);
126  }
127 
128  return true;
129  }
130 
131  return false;
132  }
+ Here is the call graph for this function:

Field Documentation

◆ $encoderFactory

ilSetupPasswordManager::$encoderFactory
private

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

Referenced by getEncoderFactory(), and setEncoderFactory().

◆ $encoderName

ilSetupPasswordManager::$encoderName
private

Definition at line 13 of file class.ilSetupPasswordManager.php.

Referenced by getEncoderName(), and setEncoderName().


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