2019-06-20 20:14:54 +02:00
|
|
|
<?php
|
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (C) 2019 Easter-eggs
|
2021-04-13 18:04:19 +02:00
|
|
|
* http://ldapsaisie.org
|
2019-06-20 20:14:54 +02:00
|
|
|
*
|
|
|
|
* Author: See AUTHORS file in top-level directory.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that password is different of another attribute of this user
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*/
|
|
|
|
class LSformRule_differentPassword extends LSformRule {
|
|
|
|
|
2021-07-21 16:34:46 +02:00
|
|
|
// CLI parameters autocompleters
|
2022-12-31 21:15:19 +01:00
|
|
|
protected static array $cli_params_autocompleters = array(
|
2021-07-21 16:34:46 +02:00
|
|
|
'otherPasswordAttributes' => null,
|
|
|
|
);
|
|
|
|
|
2019-06-20 20:14:54 +02:00
|
|
|
/**
|
2022-12-31 21:15:19 +01:00
|
|
|
* Validate form element value
|
2019-06-20 20:14:54 +02:00
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param mixed $value The value to validate
|
|
|
|
* @param array $options Validation options:
|
2020-02-18 12:31:13 +01:00
|
|
|
* - Other attribute : $options['params']['otherPasswordAttributes']
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param LSformElement &$formElement The related LSformElement object
|
2019-06-20 20:14:54 +02:00
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @return boolean True if value is valid, False otherwise
|
2019-06-20 20:14:54 +02:00
|
|
|
*/
|
2022-12-31 02:31:21 +01:00
|
|
|
public static function validate($value, $options, &$formElement) {
|
2020-02-18 12:31:13 +01:00
|
|
|
$otherPasswordAttributes = LSconfig :: get('params.otherPasswordAttributes', null, null, $options);
|
|
|
|
if (!is_null($otherPasswordAttributes)) {
|
2019-06-20 20:14:54 +02:00
|
|
|
// Load LSattr_ldap_password
|
|
|
|
if (!LSsession :: loadLSclass("LSattr_ldap_password")) {
|
|
|
|
LSerror :: addErrorCode('LSformRule_differentPassword_02');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iter on otherPasswordAttributes to check password does not match
|
2020-11-30 19:43:52 +01:00
|
|
|
foreach(ensureIsArray($otherPasswordAttributes) as $attr) {
|
2019-06-20 20:14:54 +02:00
|
|
|
// Check attribute exist
|
|
|
|
if (!isset($formElement -> attr_html -> attribute -> ldapObject -> attrs[$attr])) {
|
|
|
|
LSerror :: addErrorCode('LSformRule_differentPassword_03', $attr);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check is not the same attribute of the current one
|
|
|
|
if ($formElement -> attr_html -> attribute -> name == $attr) {
|
|
|
|
LSerror :: addErrorCode('LSformRule_differentPassword_04');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-10 18:45:00 +02:00
|
|
|
// Check attribute use LSldap_attr :: password type
|
2019-06-20 20:14:54 +02:00
|
|
|
if (!$formElement -> attr_html -> attribute -> ldapObject -> attrs[$attr] -> ldap instanceof LSattr_ldap_password) {
|
|
|
|
LSerror :: addErrorCode('LSformRule_differentPassword_05', $attr);
|
|
|
|
return false;
|
2021-06-10 18:45:00 +02:00
|
|
|
}
|
2019-06-20 20:14:54 +02:00
|
|
|
|
|
|
|
if ($formElement -> attr_html -> attribute -> ldapObject -> attrs[$attr] -> ldap -> verify($value, $formElement -> form -> getValue($attr))) {
|
|
|
|
LSdebug($formElement -> name . " : Password matched with attribute $attr");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
LSdebug($formElement -> name . " : Password does not match with $attr");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LSerror :: addErrorCode('LSformRule_differentPassword_01');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Error Codes
|
|
|
|
*/
|
|
|
|
LSerror :: defineError('LSformRule_differentPassword_01',
|
2020-08-25 17:31:50 +02:00
|
|
|
___("LSformRule_differentPassword : Other password attribute is not configured.")
|
2019-06-20 20:14:54 +02:00
|
|
|
);
|
|
|
|
LSerror :: defineError('LSformRule_differentPassword_02',
|
2020-08-25 17:31:50 +02:00
|
|
|
___("LSformRule_differentPassword : Fail to load LSattr_ldap :: password class.")
|
2019-06-20 20:14:54 +02:00
|
|
|
);
|
|
|
|
LSerror :: defineError('LSformRule_differentPassword_03',
|
2020-08-25 17:31:50 +02:00
|
|
|
___("LSformRule_differentPassword : The other password attribute %{attr} does not exist.")
|
2019-06-20 20:14:54 +02:00
|
|
|
);
|
|
|
|
LSerror :: defineError('LSformRule_differentPassword_04',
|
2020-08-25 17:31:50 +02:00
|
|
|
___("LSformRule_differentPassword : The other password attribute could not be the same of the current one.")
|
2019-06-20 20:14:54 +02:00
|
|
|
);
|
|
|
|
LSerror :: defineError('LSformRule_differentPassword_05',
|
2020-08-25 17:31:50 +02:00
|
|
|
___("LSformRule_differentPassword : The other password attributes must use LSattr_ldap :: password. It's not the case of the attribure %{attr}.")
|
2019-06-20 20:14:54 +02:00
|
|
|
);
|