mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-02-11 18:32:32 +01:00
Qual: Simplification du code sur modif mots de passe
This commit is contained in:
@@ -560,7 +560,7 @@ class Adherent extends CommonObject
|
||||
if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted)
|
||||
{
|
||||
// Si mot de passe saisi et different de celui en base
|
||||
$result=$this->password($user,$this->pass,0,$notrigger);
|
||||
$result=$this->setPassword($user,$this->pass,0,$notrigger);
|
||||
|
||||
if (! $nbrowsaffected) $nbrowsaffected++;
|
||||
}
|
||||
@@ -787,7 +787,7 @@ class Adherent extends CommonObject
|
||||
|
||||
if ($result >= 0)
|
||||
{
|
||||
$result=$luser->password($user,$this->pass,$conf->password_encrypted,0,0,1);
|
||||
$result=$luser->setPassword($user,$this->pass,0,0,1);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error=$luser->error;
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
* $Source$
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -35,8 +34,8 @@ $langs->load("other");
|
||||
|
||||
if (!$user->admin) accessforbidden();
|
||||
|
||||
// Do not allow change to clear model once passwords are crypted
|
||||
$allow_disable_encryption=false;
|
||||
// Allow/Disallow change to clear passwords once passwords are crypted
|
||||
$allow_disable_encryption=true;
|
||||
|
||||
$mesg = '';
|
||||
|
||||
@@ -264,25 +263,25 @@ $var=!$var;
|
||||
print "<tr ".$bc[$var].">";
|
||||
print '<td colspan="3">'.$langs->trans("DoNotStoreClearPassword").'</td>';
|
||||
print '<td align="center" width="60">';
|
||||
if($conf->global->DATABASE_PWD_ENCRYPTED == 1)
|
||||
if ($conf->global->DATABASE_PWD_ENCRYPTED)
|
||||
{
|
||||
print img_tick();
|
||||
}
|
||||
print '</td>';
|
||||
if ($conf->global->DATABASE_PWD_ENCRYPTED == 0)
|
||||
if (! $conf->global->DATABASE_PWD_ENCRYPTED)
|
||||
{
|
||||
print '<td align="center" width="100">';
|
||||
print '<a href="security.php?action=activate_encrypt">'.$langs->trans("Activate").'</a>';
|
||||
print "</td>";
|
||||
}
|
||||
if($conf->global->DATABASE_PWD_ENCRYPTED == 1)
|
||||
if($conf->global->DATABASE_PWD_ENCRYPTED)
|
||||
{
|
||||
print '<td align="center" width="100">';
|
||||
if ($allow_disable_encryption)
|
||||
{
|
||||
//On n'autorise pas l'annulation de l'encryption car les mots de passe ne peuvent pas <20>tre d<>cod<6F>s
|
||||
//Do not allow "disable encryption" as passwords cannot be decrypted
|
||||
print '<a href="security.php?action=disable_encrypt">'.$langs->trans("Disable").'</a>';
|
||||
//Do not allow "disable encryption" as passwords cannot be decrypted
|
||||
print '<a href="security.php?action=disable_encrypt">'.$langs->trans("Disable").'</a>';
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -346,9 +346,6 @@ class Conf
|
||||
* Modification de quelques variable de conf en fonction des Constantes
|
||||
*/
|
||||
|
||||
// Cryped password in database
|
||||
$this->password_encrypted=(! empty($this->global->DATABASE_PWD_ENCRYPTED) ? 1 : 0);
|
||||
|
||||
// System tools
|
||||
if (! $this->global->SYSTEMTOOLS_MYSQLDUMP) $this->global->SYSTEMTOOLS_MYSQLDUMP="mysqldump";
|
||||
|
||||
|
||||
@@ -197,17 +197,6 @@ if (! isset($_SESSION["dol_login"]))
|
||||
if (! empty($_POST["username"]))
|
||||
{
|
||||
// If test username/password asked, we define $test=false and $login var if ok, set $_SESSION["dol_loginmesg"] if ko
|
||||
// \TODO Virer ce test et toujours faire le test sur le champ crypte
|
||||
if ($conf->password_encrypted)
|
||||
{
|
||||
$cryptType = "md5";
|
||||
$fieldtotest="pass_crypted";
|
||||
}
|
||||
else
|
||||
{
|
||||
$cryptType = "none";
|
||||
$fieldtotest="pass";
|
||||
}
|
||||
$table = MAIN_DB_PREFIX."user";
|
||||
$usernamecol = 'login';
|
||||
|
||||
@@ -227,10 +216,15 @@ if (! isset($_SESSION["dol_login"]))
|
||||
$passtyped=$_POST["password"];
|
||||
|
||||
$passok=false;
|
||||
|
||||
// Check crypted password
|
||||
$cryptType='';
|
||||
if ($conf->global->DATABASE_PWD_ENCRYPTED) $cryptType='md5';
|
||||
if ($cryptType == 'md5')
|
||||
{
|
||||
if (md5($passtyped) == $passcrypted) $passok=true;
|
||||
}
|
||||
|
||||
// For compatibility with old versions
|
||||
if (! $passok)
|
||||
{
|
||||
|
||||
@@ -863,7 +863,7 @@ class User extends CommonObject
|
||||
$result=$this->create();
|
||||
if ($result > 0)
|
||||
{
|
||||
$result=$this->password($user,$this->pass,$conf->password_encrypted);
|
||||
$result=$this->setPassword($user,$this->pass);
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."user";
|
||||
$sql.= " SET fk_member=".$member->id;
|
||||
@@ -996,7 +996,7 @@ class User extends CommonObject
|
||||
if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted)
|
||||
{
|
||||
// Si mot de passe saisi et different de celui en base
|
||||
$result=$this->password($user,$this->pass,$conf->password_encrypted,0,$notrigger);
|
||||
$result=$this->setPassword($user,$this->pass,0,$notrigger);
|
||||
|
||||
if (! $nbrowsaffected) $nbrowsaffected++;
|
||||
}
|
||||
@@ -1141,20 +1141,19 @@ class User extends CommonObject
|
||||
/**
|
||||
* \brief Change le mot de passe d'un utilisateur
|
||||
* \param user Object user de l'utilisateur qui fait la modification
|
||||
* \param password Nouveau mot de passe (e generer si non communique)
|
||||
* \param noclearpassword 0 ou 1 s'il ne faut pas stocker le mot de passe en clair
|
||||
* \param password Nouveau mot de passe en clair (a generer si non communique)
|
||||
* \param changelater 1=Change password only after clicking on confirm email
|
||||
* \param notrigger 1=Ne declenche pas les triggers
|
||||
* \param nosyncmember Do not synchronize linked member
|
||||
* \return string If OK return clear password, 0 if no change, < 0 if error
|
||||
*/
|
||||
function password($user, $password='', $noclearpassword=0, $changelater=0, $notrigger=0, $nosyncmember=0)
|
||||
function setPassword($user, $password='', $changelater=0, $notrigger=0, $nosyncmember=0)
|
||||
{
|
||||
global $conf, $langs;
|
||||
|
||||
$error=0;
|
||||
|
||||
dolibarr_syslog("User::Password user=".$user->id." password=".eregi_replace('.','*',$password)." noclearpassword=".$noclearpassword." changelater=".$changelater." notrigger=".$notrigger);
|
||||
dolibarr_syslog("User::Password user=".$user->id." password=".eregi_replace('.','*',$password)." changelater=".$changelater." notrigger=".$notrigger);
|
||||
|
||||
// Si nouveau mot de passe non communique, on genere par module
|
||||
if (! $password)
|
||||
@@ -1173,7 +1172,7 @@ class User extends CommonObject
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."user";
|
||||
$sql.= " SET pass_crypted = '".addslashes($password_crypted)."',";
|
||||
$sql.= " pass_temp = null";
|
||||
if ($noclearpassword)
|
||||
if (! empty($conf->global->DATABASE_PWD_ENCRYPTED))
|
||||
{
|
||||
$sql.= ", pass = null";
|
||||
}
|
||||
@@ -1205,7 +1204,7 @@ class User extends CommonObject
|
||||
|
||||
if ($result >= 0)
|
||||
{
|
||||
$result=$adh->password($user,$this->pass,0,0,1); // Cryptage non gere dans module adherent
|
||||
$result=$adh->setPassword($user,$this->pass,0,1); // Cryptage non gere dans module adherent
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error=$adh->error;
|
||||
|
||||
@@ -46,7 +46,7 @@ $candisableperms=($user->admin || $user->rights->user->user->supprimer);
|
||||
// Defini si peux lire/modifier info user ou mot de passe
|
||||
if ($_GET["id"])
|
||||
{
|
||||
// $user est le user qui edite, $_GET["id"] est l'id de l'utilisateur edit<69>
|
||||
// $user est le user qui edite, $_GET["id"] est l'id de l'utilisateur edit<69>
|
||||
$caneditfield=( (($user->id == $_GET["id"]) && $user->rights->user->self->creer)
|
||||
|| (($user->id != $_GET["id"]) && $user->rights->user->user->creer) );
|
||||
$caneditpassword=( (($user->id == $_GET["id"]) && $user->rights->user->self->password)
|
||||
@@ -164,7 +164,7 @@ if ($_POST["action"] == 'add' && $canadduser)
|
||||
{
|
||||
if (isset($_POST['password']) && trim($_POST['password']))
|
||||
{
|
||||
$edituser->password($user,trim($_POST['password']),$conf->password_encrypted);
|
||||
$edituser->setPassword($user,trim($_POST['password']),$conf->global->DATABASE_PWD_ENCRYPTED);
|
||||
}
|
||||
|
||||
$db->commit();
|
||||
@@ -261,7 +261,7 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $caneditfield)
|
||||
}
|
||||
if ($ret >= 0 && isset($_POST["password"]) && $_POST["password"] !='')
|
||||
{
|
||||
$ret=$edituser->password($user,$_POST["password"],$conf->password_encrypted,1);
|
||||
$ret=$edituser->setPassword($user,$_POST["password"],1);
|
||||
if ($ret < 0)
|
||||
{
|
||||
$message.='<div class="error">'.$edituser->error.'</div>';
|
||||
@@ -303,7 +303,7 @@ if ((($_POST["action"] == 'confirm_password' && $_POST["confirm"] == 'yes')
|
||||
$edituser = new User($db, $_GET["id"]);
|
||||
$edituser->fetch();
|
||||
|
||||
$newpassword=$edituser->password($user,'',$conf->password_encrypted);
|
||||
$newpassword=$edituser->setPassword($user,'');
|
||||
if ($newpassword < 0)
|
||||
{
|
||||
// Echec
|
||||
@@ -398,7 +398,7 @@ if (($action == 'create') || ($action == 'adduserldap'))
|
||||
{
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* Affichage fiche en mode cr<63>ation */
|
||||
/* Affichage fiche en mode cr<63>ation */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -667,7 +667,7 @@ if (($action == 'create') || ($action == 'adduserldap'))
|
||||
}
|
||||
print "</td></tr>\n";
|
||||
|
||||
// Autres caract<63>ristiques issus des autres modules
|
||||
// Autres caract<63>ristiques issus des autres modules
|
||||
|
||||
// Module Webcalendar
|
||||
if ($conf->webcal->enabled)
|
||||
@@ -716,7 +716,7 @@ else
|
||||
$message .= $ldap->error;
|
||||
}
|
||||
|
||||
//On v<>rifie les options du compte
|
||||
//On v<>rifie les options du compte
|
||||
foreach ($ldap->uacf as $key => $statut)
|
||||
{
|
||||
if ($key == 65536)
|
||||
@@ -740,7 +740,7 @@ else
|
||||
|
||||
|
||||
/*
|
||||
* Confirmation r<>initialisation mot de passe
|
||||
* Confirmation r<>initialisation mot de passe
|
||||
*/
|
||||
if ($action == 'password')
|
||||
{
|
||||
@@ -758,7 +758,7 @@ else
|
||||
}
|
||||
|
||||
/*
|
||||
* Confirmation d<>sactivation
|
||||
* Confirmation d<>sactivation
|
||||
*/
|
||||
if ($action == 'disable')
|
||||
{
|
||||
@@ -940,7 +940,7 @@ else
|
||||
print '<td>'.dolibarr_print_date($fuser->datepreviouslogin,"dayhour").'</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
// Autres caract<63>ristiques issus des autres modules
|
||||
// Autres caract<63>ristiques issus des autres modules
|
||||
|
||||
// Module Webcalendar
|
||||
if ($conf->webcal->enabled)
|
||||
@@ -963,7 +963,7 @@ else
|
||||
print "</tr>\n";
|
||||
}
|
||||
|
||||
// Module Adh<64>rent
|
||||
// Module Adh<64>rent
|
||||
if ($conf->adherent->enabled)
|
||||
{
|
||||
$langs->load("members");
|
||||
@@ -1048,7 +1048,7 @@ else
|
||||
|
||||
print_fiche_titre($langs->trans("ListOfGroupsForUser"));
|
||||
|
||||
// On s<>lectionne les groups
|
||||
// On s<>lectionne les groups
|
||||
$uss = array();
|
||||
|
||||
$sql = "SELECT ug.rowid, ug.nom ";
|
||||
@@ -1094,7 +1094,7 @@ else
|
||||
}
|
||||
|
||||
/*
|
||||
* Groupes affect<63>s
|
||||
* Groupes affect<63>s
|
||||
*/
|
||||
$sql = "SELECT g.rowid, g.nom ";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."usergroup as g";
|
||||
@@ -1384,7 +1384,7 @@ else
|
||||
print $fuser->getLibStatut(4);
|
||||
print '</td></tr>';
|
||||
|
||||
// Autres caract<63>ristiques issus des autres modules
|
||||
// Autres caract<63>ristiques issus des autres modules
|
||||
|
||||
// Module Webcalendar
|
||||
if ($conf->webcal->enabled)
|
||||
|
||||
@@ -68,7 +68,7 @@ if ($_GET["action"] == 'validatenewpassword' && $_GET["username"] && $_GET["pass
|
||||
{
|
||||
if (md5($edituser->pass_temp) == $_GET["passwordmd5"])
|
||||
{
|
||||
$newpassword=$edituser->password($user,$edituser->pass_temp,$conf->password_encrypted,0);
|
||||
$newpassword=$edituser->setPassword($user,$edituser->pass_temp,0);
|
||||
dolibarr_syslog("passwordforgotten.php new password for user->id=".$edituser->id." validated in database");
|
||||
//session_start();
|
||||
//$_SESSION["loginmesg"]=$langs->trans("PasswordChanged");
|
||||
@@ -112,7 +112,7 @@ if ($_POST["action"] == 'buildnewpassword' && $_POST["username"])
|
||||
}
|
||||
else
|
||||
{
|
||||
$newpassword=$edituser->password($user,'',$conf->password_encrypted,1);
|
||||
$newpassword=$edituser->setPassword($user,'',1);
|
||||
if ($newpassword < 0)
|
||||
{
|
||||
// Echec
|
||||
|
||||
Reference in New Issue
Block a user