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

Public Member Functions

 __construct (array $config=array())
 Please use the singleton method for instance creation The constructor is still public because of the unit tests. More...
 
 getEncoderName ()
 
 setEncoderName ($encoder_name)
 
 getEncoderFactory ()
 
 setEncoderFactory (ilUserPasswordEncoderFactory $encoder_factory)
 
 encodePassword (ilObjUser $user, $raw)
 
 isEncodingTypeSupported ($name)
 
 verifyPassword (ilObjUser $user, $raw)
 

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

 $encoder_factory
 
 $encoder_name
 
 $config = array()
 

Static Private Attributes

static $instance
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

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

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 44 of file class.ilUserPasswordManager.php.

45 {
46 if (!empty($config)) {
47 foreach ($config as $key => $value) {
48 switch (strtolower($key)) {
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('"encoder_factory" must be instance of ilUserPasswordEncoderFactory and set in %s.', json_encode($config)));
65 }
66 }
Class for user related exception handling in ILIAS.
setEncoderFactory(ilUserPasswordEncoderFactory $encoder_factory)
$key
Definition: croninfo.php:18

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

+ Here is the call graph for this function:

Member Function Documentation

◆ encodePassword()

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

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

133 {
134 $encoder = $this->getEncoderFactory()->getEncoderByName($this->getEncoderName());
135 $user->setPasswordEncodingType($encoder->getName());
136 if ($encoder->requiresSalt()) {
137 require_once 'Services/Password/classes/class.ilPasswordUtils.php';
138 $user->setPasswordSalt(
139 substr(str_replace('+', '.', base64_encode(ilPasswordUtils::getBytes(self::MIN_SALT_SIZE))), 0, 22)
140 );
141 } else {
142 $user->setPasswordSalt(null);
143 }
144 $user->setPasswd($encoder->encodePassword($raw, $user->getPasswordSalt()), IL_PASSWD_CRYPTED);
145 }
const IL_PASSWD_CRYPTED
setPasswordEncodingType($password_encryption_type)
static getBytes($length)
Generate random bytes using OpenSSL or Mcrypt and mt_rand() as fallback.
$user
Definition: migrateto20.php:57

References $user, ilPasswordUtils\getBytes(), getEncoderFactory(), getEncoderName(), IL_PASSWD_CRYPTED, and ilObjUser\setPasswordEncodingType().

+ Here is the call graph for this function:

◆ getEncoderFactory()

ilUserPasswordManager::getEncoderFactory ( )
Returns
ilUserPasswordEncoderFactory

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

References $encoder_factory.

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

+ Here is the caller graph for this function:

◆ getEncoderName()

ilUserPasswordManager::getEncoderName ( )
Returns
string

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

References $encoder_name.

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

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

73 {
74 if (self::$instance instanceof self) {
75 return self::$instance;
76 }
77
78 require_once 'Services/User/classes/class.ilUserPasswordEncoderFactory.php';
79 $password_manager = new ilUserPasswordManager(
80 array(
81 'encoder_factory' => new ilUserPasswordEncoderFactory(
82 array(
83 'default_password_encoder' => 'bcryptphp',
84 'ignore_security_flaw' => true,
85 'data_directory' => ilUtil::getDataDir()
86 )
87 ),
88 'password_encoder' => 'bcryptphp'
89 )
90 );
91
92 self::$instance = $password_manager;
93 return self::$instance;
94 }
static getDataDir()
get data directory (outside webspace)

References $instance, and ilUtil\getDataDir().

Referenced by ilPDNewsBlockGUI\changeFeedSettings(), 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 (   $name)
Parameters
string$name
Returns
bool

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

152 {
153 return in_array($name, $this->getEncoderFactory()->getSupportedEncoderNames());
154 }

References $name, and getEncoderFactory().

+ Here is the call graph for this function:

◆ setEncoderFactory()

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

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

124 {
125 $this->encoder_factory = $encoder_factory;
126 }

References $encoder_factory.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setEncoderName()

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

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

108 {
109 $this->encoder_name = $encoder_name;
110 }

References $encoder_name.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ verifyPassword()

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

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

162 {
163 $encoder = $this->getEncoderFactory()->getEncoderByName($user->getPasswordEncodingType(), true);
164 if ($this->getEncoderName() != $encoder->getName()) {
165 if ($encoder->isPasswordValid($user->getPasswd(), $raw, $user->getPasswordSalt())) {
166 $user->resetPassword($raw, $raw);
167 return true;
168 }
169 } elseif ($encoder->isPasswordValid($user->getPasswd(), $raw, $user->getPasswordSalt())) {
170 if ($encoder->requiresReencoding($user->getPasswd())) {
171 $user->resetPassword($raw, $raw);
172 }
173
174 return true;
175 }
176
177 return false;
178 }

References $user, getEncoderFactory(), getEncoderName(), and ilObjUser\getPasswordEncodingType().

+ Here is the call graph for this function:

Field Documentation

◆ $config

ilUserPasswordManager::$config = array()
protected

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

Referenced by __construct().

◆ $encoder_factory

ilUserPasswordManager::$encoder_factory
protected

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

Referenced by getEncoderFactory(), and setEncoderFactory().

◆ $encoder_name

ilUserPasswordManager::$encoder_name
protected

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

Referenced by getEncoderName(), and setEncoderName().

◆ $instance

ilUserPasswordManager::$instance
staticprivate

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

Referenced by getInstance().

◆ MIN_SALT_SIZE

const ilUserPasswordManager::MIN_SALT_SIZE = 16

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


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