ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilUserPasswordEncoderFactory Class Reference
+ Inheritance diagram for ilUserPasswordEncoderFactory:
+ Collaboration diagram for ilUserPasswordEncoderFactory:

Public Member Functions

 __construct (array $config=array())
 
 getDefaultEncoder ()
 
 setDefaultEncoder ($default_encoder)
 
 getEncoders ()
 
 setEncoders (array $encoders)
 
 getSupportedEncoderNames ()
 
 getEncoderByName ($name, $get_default_on_mismatch=false)
 
 getFirstEncoderForEncodedPasswordAndMatchers (string $encoded, array $matchers)
 

Protected Member Functions

 getValidEncoders ($config)
 
 initEncoders (array $config)
 

Protected Attributes

 $default_encoder
 
 $encoders = array()
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilUserPasswordEncoderFactory::__construct ( array  $config = array())
Parameters
array$config

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

27 {
28 if (!empty($config)) {
29 foreach ($config as $key => $value) {
30 switch (strtolower($key)) {
31 case 'default_password_encoder':
32 $this->setDefaultEncoder($value);
33 break;
34 }
35 }
36 }
37
38 $this->initEncoders($config);
39 }
$key
Definition: croninfo.php:18
$config
Definition: bootstrap.php:15

References $config, $key, initEncoders(), and setDefaultEncoder().

+ Here is the call graph for this function:

Member Function Documentation

◆ getDefaultEncoder()

ilUserPasswordEncoderFactory::getDefaultEncoder ( )
Returns
string

Definition at line 73 of file class.ilUserPasswordEncoderFactory.php.

References $default_encoder.

Referenced by getEncoderByName(), and getFirstEncoderForEncodedPasswordAndMatchers().

+ Here is the caller graph for this function:

◆ getEncoderByName()

ilUserPasswordEncoderFactory::getEncoderByName (   $name,
  $get_default_on_mismatch = false 
)
Parameters
string$name
bool$get_default_on_mismatch
Returns
\ilPasswordEncoder
Exceptions

ilUserException

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

124 {
125 if (!isset($this->encoders[$name])) {
126 if (!$get_default_on_mismatch) {
127 throw new \ilUserException(sprintf('The encoder "%s" was not configured.', $name));
128 } elseif (!$this->getDefaultEncoder()) {
129 throw new \ilUserException('No default encoder specified, fallback not possible.');
130 } elseif (!isset($this->encoders[$this->getDefaultEncoder()])) {
131 throw new \ilUserException("No default encoder found for name: '{$this->getDefaultEncoder()}'.");
132 }
133
134 return $this->encoders[$this->getDefaultEncoder()];
135 }
136
137 return $this->encoders[$name];
138 }

References $name, and getDefaultEncoder().

Referenced by getFirstEncoderForEncodedPasswordAndMatchers().

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

◆ getEncoders()

ilUserPasswordEncoderFactory::getEncoders ( )
Returns
\ilPasswordEncoder[]

Definition at line 89 of file class.ilUserPasswordEncoderFactory.php.

References $encoders.

Referenced by getFirstEncoderForEncodedPasswordAndMatchers(), and getSupportedEncoderNames().

+ Here is the caller graph for this function:

◆ getFirstEncoderForEncodedPasswordAndMatchers()

ilUserPasswordEncoderFactory::getFirstEncoderForEncodedPasswordAndMatchers ( string  $encoded,
array  $matchers 
)
Parameters
string$encoded
array$matchersAn key/value pair callback functions (accepting the encoded password) assigned to the respective encoder name
Returns
\ilPasswordEncoder
Exceptions

ilUserException

Definition at line 146 of file class.ilUserPasswordEncoderFactory.php.

147 {
148 foreach ($this->getEncoders() as $encoder) {
149 foreach ($matchers as $encoderName => $callback) {
150 if (
151 $encoder->getName() === $encoderName &&
152 is_callable($callback) && $callback($encoded) === true
153 ) {
154 return $encoder;
155 }
156 }
157 }
158
159 return $this->getEncoderByName($this->getDefaultEncoder());
160 }
getEncoderByName($name, $get_default_on_mismatch=false)

References getDefaultEncoder(), getEncoderByName(), and getEncoders().

+ Here is the call graph for this function:

◆ getSupportedEncoderNames()

ilUserPasswordEncoderFactory::getSupportedEncoderNames ( )
Returns
string[]

Definition at line 112 of file class.ilUserPasswordEncoderFactory.php.

113 {
114 return array_keys($this->getEncoders());
115 }

References getEncoders().

+ Here is the call graph for this function:

◆ getValidEncoders()

ilUserPasswordEncoderFactory::getValidEncoders (   $config)
protected
Parameters
array$config
Returns
\ilPasswordEncoder[]

Reimplemented in ilSetupPasswordEncoderFactory.

Definition at line 45 of file class.ilUserPasswordEncoderFactory.php.

45 : array
46 {
47 return [
48 new \ilBcryptPhpPasswordEncoder($config),
49 new \ilBcryptPasswordEncoder($config),
50 new \ilMd5PasswordEncoder($config),
51 ];
52 }

References $config.

Referenced by initEncoders().

+ Here is the caller graph for this function:

◆ initEncoders()

ilUserPasswordEncoderFactory::initEncoders ( array  $config)
protected
Parameters
array$config

Definition at line 57 of file class.ilUserPasswordEncoderFactory.php.

58 {
59 $this->encoders = [];
60
62
63 foreach ($encoders as $encoder) {
64 if ($encoder->isSupportedByRuntime()) {
65 $this->encoders[$encoder->getName()] = $encoder;
66 }
67 }
68 }

References $encoders, and getValidEncoders().

Referenced by __construct().

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

◆ setDefaultEncoder()

ilUserPasswordEncoderFactory::setDefaultEncoder (   $default_encoder)
Parameters
string$default_encoder

Definition at line 81 of file class.ilUserPasswordEncoderFactory.php.

82 {
83 $this->default_encoder = $default_encoder;
84 }

References $default_encoder.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setEncoders()

ilUserPasswordEncoderFactory::setEncoders ( array  $encoders)
Parameters
\ilPasswordEncoder[]$encoders
Exceptions

ilUserException

Definition at line 98 of file class.ilUserPasswordEncoderFactory.php.

99 {
100 $this->encoders = array();
101 foreach ($encoders as $encoder) {
102 if (!($encoder instanceof \ilPasswordEncoder)) {
103 throw new \ilUserException(sprintf('One of the passed encoders is not valid: %s.', json_encode($encoder)));
104 }
105 $this->encoders[$encoder->getName()] = $encoder;
106 }
107 }

References $encoders.

Field Documentation

◆ $default_encoder

ilUserPasswordEncoderFactory::$default_encoder
protected

Definition at line 16 of file class.ilUserPasswordEncoderFactory.php.

Referenced by getDefaultEncoder(), and setDefaultEncoder().

◆ $encoders

ilUserPasswordEncoderFactory::$encoders = array()
protected

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

Referenced by getEncoders(), initEncoders(), and setEncoders().


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