36 protected $lockable = TRUE;
61 abstract public function generate_hash (
string $pwd,
bool $locked = FALSE): string;
90 return $this->lockable;
101 if (!$this->lockable) {
107 $ldap = $config->get_ldap_link();
108 $ldap->cd($config->current[
'BASE']);
109 $ldap->cat($dn, [
'userPassword']);
110 $attrs = $ldap->fetch();
111 if (isset($attrs[
'userPassword'][0])) {
112 $pwd = $attrs[
'userPassword'][0];
115 return preg_match(
"/^[^\}]*+\}!/", $pwd);
128 return $this->generic_modify_account($dn,
'LOCK', $lockEverything);
137 return $this->generic_modify_account($dn,
'UNLOCK');
144 private function generic_modify_account ($dn,
string $mode,
bool $lockEverything = TRUE)
147 if (!$this->lockable) {
150 if ($mode !=
'LOCK' && $mode !=
'UNLOCK') {
156 $userMainTab = $userObject->getBaseObject();
159 if ($userMainTab->attributesAccess[
'userPassword']->isLocked()) {
160 if ($mode ==
'LOCK') {
163 } elseif ($mode ==
'UNLOCK') {
170 if ($lockEverything) {
171 foreach ($userObject->by_object as $tab) {
174 $tab->fillLockingLDAPAttrs($mode, $modify);
182 $errors = $userMainTab->callHook(
'PRE'.$mode, [], $ret);
183 if (!empty($errors)) {
184 msg_dialog::displayChecks($errors);
189 $pwd = $userMainTab->attributesAccess[
'userPassword']->computeLdapValue();
192 if ($mode ==
'LOCK') {
195 $pwd = passwordMethodEmpty::LOCKVALUE;
197 $pwd = preg_replace(
"/(^[^\}]+\})(.*$)/",
"\\1!\\2", $pwd);
201 if ($pwd == passwordMethodEmpty::LOCKVALUE) {
204 $pwd = preg_replace(
"/(^[^\}]+\})!(.*$)/",
"\\1\\2", $pwd);
207 $modify[
'userPassword'] = $pwd;
209 $ldap = $config->get_ldap_link();
211 $ldap->modify($modify);
214 if ($ldap->success()) {
215 $userClass =
new user($dn);
216 $errors = $userClass->callHook(
'POST'.$mode, [], $ret);
217 if (!empty($errors)) {
218 msg_dialog::displayChecks($errors);
224 return $ldap->success();
233 global $class_mapping;
238 foreach (array_keys($class_mapping) as $class) {
239 if (preg_match(
'/^passwordMethod.+/i', $class)) {
240 $test =
new $class(
'');
241 if ($test->is_available()) {
242 $plugs = $test->get_hash_name();
243 if (!is_array($plugs)) {
247 $cfg = $test->is_configurable();
249 foreach ($plugs as $plugname) {
250 $ret[
'name'][$i] = $plugname;
251 $ret[
'class'][$i] = $class;
252 $ret[
'is_configurable'][$i] = $cfg;
253 $ret[
'object'][$i] = $test;
255 $ret[$i][
'name'] = $plugname;
256 $ret[$i][
'class'] = $class;
257 $ret[$i][
'object'] = $test;
258 $ret[$i][
'is_configurable'] = $cfg;
260 $ret[$plugname] = $class;
266 session::set(
'passwordMethod::get_available_methods', $ret);
268 return session::get(
'passwordMethod::get_available_methods');
318 if (isset($methods[
'class'][
'passwordMethodEmpty']) && (passwordMethodEmpty::_extract_method($password_hash) !=
'')) {
324 foreach ($methods[
'class'] as $class) {
325 $method = $class::_extract_method($password_hash);
327 $test =
new $class($dn);
328 $test->set_hash($method);
346 $hash = static::get_hash_name();
347 if (preg_match(
"/^\{$hash\}/i", $password_hash)) {
364 $tmp =
new $methods[$hash]();
365 $tmp->set_hash($hash);
366 return $tmp->generate_hash($password);
398 if ($config->get_cfg_value(
'strictPasswordRules') ==
'TRUE') {
400 return ($password == utf8_decode($password));
static is_harmless($password)
Test for problematic unicode caracters in password This can be activated with the keyword strictPassw...
This class contains all the functions for clear password method.
static get_hash_name()
Get the Hash name.
static get($name)
Accessor of a session var.
checkPassword($pwd, $hash)
Method to check if a password matches a hash.
static _extract_method($password_hash)
Extract a method.
is_lockable()
If we can lock the password.
static make_hash($password, $hash)
Make a hash.
is_available()
Is available.
__construct($dn='', $userTab=NULL)
Password method contructor.
generate_hash(string $pwd, bool $locked=FALSE)
Generate template hash.
static set($name, $value)
Set a value in a session.
configure()
Provide a subdialog to configure a password method.
This interface is implemented when a user tabs needs to alter the locking LDAP modification for users...
Error returned by an LDAP operation called from FusionDirectory.
lock_account($dn='', bool $lockEverything=TRUE)
Locks an account by adding a '!' as prefix to the password hashes. This makes login impossible...
is_configurable()
Return true if this password method provides a configuration dialog.
static open(string $dn, string $type)
Create the tab object for the given dn.
Parent class for all exceptions thrown in FusionDirectory.
This class contains all the functions for empty password method.
is_locked($dn='', $pwd='')
Is locked.
static get_available_methods()
This function returns all loaded classes for password encryption.
This class contains all the basic function for password methods.
need_password()
If we need password.
static get_method($password_hash, $dn='')
Try to find out if it's our hash...
save($dn)
Save information to LDAP.
set_hash($hash)
Set a hash.
static is_set($name)
Check if the name of the session is set.
unlock_account($dn='')
Unlocks an account which was locked by 'lock_account()'. For details about the locking mechanism see ...