ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 21 of file class.ilSetupPasswordManager.php.

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

22  {
23  if (!empty($config)) {
24  foreach ($config as $key => $value) {
25  switch (strtolower($key)) {
26  case 'password_encoder':
27  $this->setEncoderName($value);
28  break;
29 
30  case 'encoder_factory':
31  $this->setEncoderFactory($value);
32  break;
33  }
34  }
35  }
36 
37  if (!$this->getEncoderName()) {
38  throw new \Exception(sprintf('"password_encoder" must be set in %s.', json_encode($config)));
39  }
40 
41  if (!($this->getEncoderFactory() instanceof \ilSetupPasswordEncoderFactory)) {
42  throw new \ilUserException(sprintf(
43  '"encoder_factory" must be instance of \ilSetupPasswordEncoderFactory and set in %s.',
44  json_encode($config)
45  ));
46  }
47  }
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68
setEncoderFactory(\ilSetupPasswordEncoderFactory $encoderFactory)
+ 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 87 of file class.ilSetupPasswordManager.php.

References getEncoderFactory(), and getEncoderName().

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

◆ getEncoderFactory()

ilSetupPasswordManager::getEncoderFactory ( )
Returns

Definition at line 52 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 68 of file class.ilSetupPasswordManager.php.

References $encoderName.

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

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

◆ setEncoderFactory()

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

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

References $encoderFactory.

Referenced by __construct().

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

◆ setEncoderName()

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

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

References $encoderName.

Referenced by __construct().

76  : void
77  {
78  $this->encoderName = $encoderName;
79  }
+ 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 103 of file class.ilSetupPasswordManager.php.

References getEncoderFactory(), and getEncoderName().

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

Field Documentation

◆ $encoderFactory

ilSetupPasswordManager::$encoderFactory
private

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

Referenced by getEncoderFactory(), and setEncoderFactory().

◆ $encoderName

ilSetupPasswordManager::$encoderName
private

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

Referenced by getEncoderName(), and setEncoderName().


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