FIX: #12908 User login with credentials from self-subscription form fails

This commit is contained in:
AdrianDominik 2020-01-27 10:54:08 +01:00
parent 2cb414e17e
commit 540e82102b
2 changed files with 191 additions and 179 deletions

View File

@ -641,7 +641,7 @@ class Adherent extends CommonObject
$isencrypted = empty($conf->global->DATABASE_PWD_ENCRYPTED)?0:1; $isencrypted = empty($conf->global->DATABASE_PWD_ENCRYPTED)?0:1;
// If password to set differs from the one found into database // If password to set differs from the one found into database
$result=$this->setPassword($user, $this->pass, $isencrypted, $notrigger, $nosyncuserpass); $result=$this->setPassword($user, $this->pass, $this->pass_indatabase_crypted, $isencrypted, $notrigger, $nosyncuserpass);
if (! $nbrowsaffected) $nbrowsaffected++; if (! $nbrowsaffected) $nbrowsaffected++;
} }
} }
@ -966,7 +966,7 @@ class Adherent extends CommonObject
* @param int $nosyncuser Do not synchronize linked user * @param int $nosyncuser Do not synchronize linked user
* @return string If OK return clear password, 0 if no change, < 0 if error * @return string If OK return clear password, 0 if no change, < 0 if error
*/ */
public function setPassword($user, $password = '', $isencrypted = 0, $notrigger = 0, $nosyncuser = 0) public function setPassword($user, $password = '', $password_indatabase_crypted = '', $isencrypted = 0, $notrigger = 0, $nosyncuser = 0)
{ {
global $conf, $langs; global $conf, $langs;
@ -974,6 +974,9 @@ class Adherent extends CommonObject
dol_syslog(get_class($this)."::setPassword user=".$user->id." password=".preg_replace('/./i', '*', $password)." isencrypted=".$isencrypted); dol_syslog(get_class($this)."::setPassword user=".$user->id." password=".preg_replace('/./i', '*', $password)." isencrypted=".$isencrypted);
// If password_crypted not provided, try crypt password provided
if(!$password_indatabase_crypted)
{
// If new password not provided, we generate one // If new password not provided, we generate one
if (!$password) if (!$password)
{ {
@ -984,12 +987,11 @@ class Adherent extends CommonObject
// Crypt password // Crypt password
$password_crypted = dol_hash($password); $password_crypted = dol_hash($password);
$password_indatabase = ''; } else {
if (! $isencrypted) $password_crypted = $password_indatabase_crypted;
{
$password_indatabase = $password;
} }
$this->db->begin(); $this->db->begin();
// Mise a jour // Mise a jour
@ -1030,7 +1032,7 @@ class Adherent extends CommonObject
if ($result >= 0) if ($result >= 0)
{ {
$result=$luser->setPassword($user, $this->pass, 0, 0, 1); $result=$luser->setPassword($user, $this->pass, $this->pass_indatabase_crypted, 0, 0, 1);
if ($result < 0) if ($result < 0)
{ {
$this->error=$luser->error; $this->error=$luser->error;

View File

@ -1402,6 +1402,7 @@ class User extends CommonObject
$this->email = $member->email; $this->email = $member->email;
$this->fk_member = $member->id; $this->fk_member = $member->id;
$this->pass = $member->pass; $this->pass = $member->pass;
$this->pass_indatabase_crypted = $member->pass_indatabase_crypted;
$this->address = $member->address; $this->address = $member->address;
$this->zip = $member->zip; $this->zip = $member->zip;
$this->town = $member->town; $this->town = $member->town;
@ -1417,7 +1418,7 @@ class User extends CommonObject
$result = $this->create($user); $result = $this->create($user);
if ($result > 0) if ($result > 0)
{ {
$newpass = $this->setPassword($user, $this->pass); $newpass = $this->setPassword($user, $this->pass, $this->pass_indatabase_crypted);
if (is_numeric($newpass) && $newpass < 0) $result = -2; if (is_numeric($newpass) && $newpass < 0) $result = -2;
if ($result > 0 && $member->fk_soc) // If member is linked to a thirdparty if ($result > 0 && $member->fk_soc) // If member is linked to a thirdparty
@ -1854,7 +1855,7 @@ class User extends CommonObject
* @param int $nosyncmember Do not synchronize linked member * @param int $nosyncmember Do not synchronize linked member
* @return string If OK return clear password, 0 if no change, < 0 if error * @return string If OK return clear password, 0 if no change, < 0 if error
*/ */
public function setPassword($user, $password = '', $changelater = 0, $notrigger = 0, $nosyncmember = 0) public function setPassword($user, $password = '', $password_indatabase_crypted = '', $changelater = 0, $notrigger = 0, $nosyncmember = 0)
{ {
global $conf, $langs; global $conf, $langs;
require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
@ -1863,6 +1864,9 @@ class User extends CommonObject
dol_syslog(get_class($this)."::setPassword user=".$user->id." password=".preg_replace('/./i', '*', $password)." changelater=".$changelater." notrigger=".$notrigger." nosyncmember=".$nosyncmember, LOG_DEBUG); dol_syslog(get_class($this)."::setPassword user=".$user->id." password=".preg_replace('/./i', '*', $password)." changelater=".$changelater." notrigger=".$notrigger." nosyncmember=".$nosyncmember, LOG_DEBUG);
// If password_crypted not provided, try crypt password provided
if(!$password_indatabase_crypted)
{
// If new password not provided, we generate one // If new password not provided, we generate one
if (!$password) if (!$password)
{ {
@ -1872,6 +1876,12 @@ class User extends CommonObject
// Crypt password // Crypt password
$password_crypted = dol_hash($password); $password_crypted = dol_hash($password);
} else {
$password_crypted = $password_indatabase_crypted;
}
// Mise a jour // Mise a jour
if (!$changelater) if (!$changelater)
{ {
@ -1913,7 +1923,7 @@ class User extends CommonObject
if ($result >= 0) if ($result >= 0)
{ {
$result = $adh->setPassword($user, $this->pass, (empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1), 1); // Cryptage non gere dans module adherent $result = $adh->setPassword($user, $this->pass, $this->pass_indatabase_crypted, (empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1), 1); // Cryptage non gere dans module adherent
if ($result < 0) if ($result < 0)
{ {
$this->error = $adh->error; $this->error = $adh->error;