ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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, $migrate=true)
 

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 {
48 foreach($config as $key => $value)
49 {
50 switch(strtolower($key))
51 {
52 case 'password_encoder':
53 $this->setEncoderName($value);
54 break;
55 case 'encoder_factory':
56 $this->setEncoderFactory($value);
57 break;
58 }
59 }
60 }
61
62 if(!$this->getEncoderName())
63 {
64 throw new ilUserException(sprintf('"password_encoder" must be set in %s.', json_encode($config)));
65 }
66
67 if(!($this->getEncoderFactory() instanceof ilUserPasswordEncoderFactory))
68 {
69 throw new ilUserException(sprintf('"encoder_factory" must be instance of ilUserPasswordEncoderFactory and set in %s.', json_encode($config)));
70 }
71 }
Class for user related exception handling in ILIAS.
setEncoderFactory(ilUserPasswordEncoderFactory $encoder_factory)

References $config, 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 137 of file class.ilUserPasswordManager.php.

138 {
139 $encoder = $this->getEncoderFactory()->getEncoderByName($this->getEncoderName());
140 $user->setPasswordEncodingType($encoder->getName());
141 if($encoder->requiresSalt())
142 {
143 require_once 'Services/Password/classes/class.ilPasswordUtils.php';
144 $user->setPasswordSalt(
145 substr(str_replace('+', '.', base64_encode(ilPasswordUtils::getBytes(self::MIN_SALT_SIZE))), 0, 22)
146 );
147 }
148 else
149 {
150 $user->setPasswordSalt(null);
151 }
152 $user->setPasswd($encoder->encodePassword($raw, $user->getPasswordSalt()), IL_PASSWD_CRYPTED);
153 }
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

Definition at line 120 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 104 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 77 of file class.ilUserPasswordManager.php.

78 {
79 if(self::$instance instanceof self)
80 {
81 return self::$instance;
82 }
83
84 require_once 'Services/User/classes/class.ilUserPasswordEncoderFactory.php';
85 $password_manager = new ilUserPasswordManager(
86 array(
87 'encoder_factory' => new ilUserPasswordEncoderFactory(
88 array(
89 'default_password_encoder' => 'bcrypt',
90 'ignore_security_flaw' => true
91 )
92 ),
93 'password_encoder' => 'bcrypt'
94 )
95 );
96
97 self::$instance = $password_manager;
98 return self::$instance;
99 }

References $instance.

Referenced by ilPDNewsBlockGUI\changeFeedSettings(), ilPurchaseBMFGUI\getCreditCard(), ilPurchaseBMFGUI\getDebitEntry(), ilObjUser\isPasswordChangeDemanded(), ilSetup\loginAsClient(), and ilPersonalSettingsGUI\savePassword().

+ Here is the caller graph for this function:

◆ isEncodingTypeSupported()

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

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

160 {
161 return in_array($name, $this->getEncoderFactory()->getSupportedEncoderNames());
162 }

References getEncoderFactory().

+ Here is the call graph for this function:

◆ setEncoderFactory()

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

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

129 {
130 $this->encoder_factory = $encoder_factory;
131 }

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

113 {
114 $this->encoder_name = $encoder_name;
115 }

References $encoder_name.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ verifyPassword()

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

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

171 {
172 $encoder = $this->getEncoderFactory()->getEncoderByName($user->getPasswordEncodingType(), true);
173 if($this->getEncoderName() != $encoder->getName())
174 {
175 if($encoder->isPasswordValid($user->getPasswd(), $raw, $user->getPasswordSalt()))
176 {
177 if($migrate)
178 {
179 $user->resetPassword($raw, $raw);
180 }
181
182 return true;
183 }
184
185 return false;
186 }
187 else
188 {
189 return $encoder->isPasswordValid($user->getPasswd(), $raw, $user->getPasswordSalt());
190 }
191 }
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 = 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: