ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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.

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

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)
+ 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.

References ilPasswordUtils\getBytes(), getEncoderFactory(), getEncoderName(), ilObjUser\getPasswordSalt(), IL_PASSWD_CRYPTED, ilObjUser\setPasswd(), ilObjUser\setPasswordEncodingType(), and ilObjUser\setPasswordSalt().

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
static getBytes($length)
Generate random bytes using OpenSSL or Mcrypt and mt_rand() as fallback.
setPasswd($a_str, $a_type=IL_PASSWD_PLAIN)
set password public
setPasswordSalt($password_salt)
setPasswordEncodingType($password_encryption_type)
+ 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.

References array.

Referenced by ilObjUser\assignData(), ilPDNewsBlockGUI\changeFeedSettings(), ilObjUser\isPasswordChangeDemanded(), ilSetup\loginAsClient(), ilObjUser\refreshLogin(), ilPersonalSettingsGUI\savePassword(), ilPDOAuthentication\setAuth(), and ilAuthContainerMDB2\supportsCaptchaVerification().

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' => 'bcryptphp',
90  'ignore_security_flaw' => true
91  )
92  ),
93  'password_encoder' => 'bcryptphp'
94  )
95  );
96 
97  self::$instance = $password_manager;
98  return self::$instance;
99  }
Create styles array
The data for the language used.
+ 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.

References getEncoderFactory().

160  {
161  return in_array($name, $this->getEncoderFactory()->getSupportedEncoderNames());
162  }
+ 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.

References $encoder_factory.

Referenced by __construct().

129  {
130  $this->encoder_factory = $encoder_factory;
131  }
+ 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.

References $encoder_name.

Referenced by __construct().

113  {
114  $this->encoder_name = $encoder_name;
115  }
+ Here is the caller graph for this function:

◆ verifyPassword()

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

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

References getEncoderFactory(), getEncoderName(), ilObjUser\getPasswd(), ilObjUser\getPasswordEncodingType(), and ilObjUser\getPasswordSalt().

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

◆ 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: