NEW Invalidate all sessions of a user when password is modified.
This commit is contained in:
parent
acc30da1fe
commit
f2f4cdbe6a
@ -91,18 +91,6 @@ function check_user_password_dolibarr($usertotest, $passwordtotest, $entitytotes
|
|||||||
dol_syslog("functions_dolibarr::check_user_password_dolibarr bad date end validity", LOG_WARNING);
|
dol_syslog("functions_dolibarr::check_user_password_dolibarr bad date end validity", LOG_WARNING);
|
||||||
return '--bad-login-validity--';
|
return '--bad-login-validity--';
|
||||||
}
|
}
|
||||||
// If there is an invalidation date, check that the current session date is not before this date
|
|
||||||
if ($obj->flagdelsessionsbefore && !empty($_SESSION["dol_logindate"])) {
|
|
||||||
dol_syslog("functions_dolibarr::check_user_password_dolibarr user has a date for session invalidation = ".$obj->flagdelsessionsbefore." and session date = ".$_SESSION["dol_logindate"]);
|
|
||||||
$datetmp = $db->jdate($obj->flagdelsessionsbefore, 'gmt');
|
|
||||||
if ($datetmp > $now) {
|
|
||||||
// Load translation files required by the page
|
|
||||||
$langs->loadLangs(array('main', 'errors'));
|
|
||||||
$_SESSION["dol_loginmesg"] = $langs->transnoentitiesnoconv("ErrorSessionInvalidatedAfterPasswordChange");
|
|
||||||
dol_syslog("functions_dolibarr::check_user_password_dolibarr session was invalidated", LOG_WARNING);
|
|
||||||
return '--bad-login-validity--';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$passclear = $obj->pass;
|
$passclear = $obj->pass;
|
||||||
$passcrypted = $obj->pass_crypted;
|
$passcrypted = $obj->pass_crypted;
|
||||||
|
|||||||
@ -303,6 +303,7 @@ ErrorValueForTooLow=Value for <b>%s</b> is too low
|
|||||||
ErrorValueCantBeNull=Value for <b>%s</b> can't be null
|
ErrorValueCantBeNull=Value for <b>%s</b> can't be null
|
||||||
ErrorDateOfMovementLowerThanDateOfFileTransmission=The date of the bank transaction can't be lower than the date of the file transmission
|
ErrorDateOfMovementLowerThanDateOfFileTransmission=The date of the bank transaction can't be lower than the date of the file transmission
|
||||||
ErrorTooMuchFileInForm=Too much files in form, the maximum number is %s file(s)
|
ErrorTooMuchFileInForm=Too much files in form, the maximum number is %s file(s)
|
||||||
|
ErrorSessionInvalidatedAfterPasswordChange=The session was invalidated after a password change. Please relogin.
|
||||||
|
|
||||||
# Warnings
|
# Warnings
|
||||||
WarningParamUploadMaxFileSizeHigherThanPostMaxSize=Your PHP parameter upload_max_filesize (%s) is higher than PHP parameter post_max_size (%s). This is not a consistent setup.
|
WarningParamUploadMaxFileSizeHigherThanPostMaxSize=Your PHP parameter upload_max_filesize (%s) is higher than PHP parameter post_max_size (%s). This is not a consistent setup.
|
||||||
@ -325,6 +326,7 @@ WarningPaymentDateLowerThanInvoiceDate=Payment date (%s) is earlier than invoice
|
|||||||
WarningTooManyDataPleaseUseMoreFilters=Too many data (more than %s lines). Please use more filters or set the constant %s to a higher limit.
|
WarningTooManyDataPleaseUseMoreFilters=Too many data (more than %s lines). Please use more filters or set the constant %s to a higher limit.
|
||||||
WarningSomeLinesWithNullHourlyRate=Some times were recorded by some users while their hourly rate was not defined. A value of 0 %s per hour was used but this may result in wrong valuation of time spent.
|
WarningSomeLinesWithNullHourlyRate=Some times were recorded by some users while their hourly rate was not defined. A value of 0 %s per hour was used but this may result in wrong valuation of time spent.
|
||||||
WarningYourLoginWasModifiedPleaseLogin=Your login was modified. For security purpose you will have to login with your new login before next action.
|
WarningYourLoginWasModifiedPleaseLogin=Your login was modified. For security purpose you will have to login with your new login before next action.
|
||||||
|
WarningYourPasswordWasModifiedPleaseLogin=Your password was modified. For security purpose you will have to login now with your new password.
|
||||||
WarningAnEntryAlreadyExistForTransKey=An entry already exists for the translation key for this language
|
WarningAnEntryAlreadyExistForTransKey=An entry already exists for the translation key for this language
|
||||||
WarningNumberOfRecipientIsRestrictedInMassAction=Warning, number of different recipient is limited to <b>%s</b> when using the mass actions on lists
|
WarningNumberOfRecipientIsRestrictedInMassAction=Warning, number of different recipient is limited to <b>%s</b> when using the mass actions on lists
|
||||||
WarningDateOfLineMustBeInExpenseReportRange=Warning, the date of line is not in the range of the expense report
|
WarningDateOfLineMustBeInExpenseReportRange=Warning, the date of line is not in the range of the expense report
|
||||||
|
|||||||
@ -943,26 +943,35 @@ if (!defined('NOLOGIN')) {
|
|||||||
dol_syslog("- This is an already logged session. _SESSION['dol_login']=".$login." _SESSION['dol_entity']=".$entity, LOG_DEBUG);
|
dol_syslog("- This is an already logged session. _SESSION['dol_login']=".$login." _SESSION['dol_entity']=".$entity, LOG_DEBUG);
|
||||||
|
|
||||||
$resultFetchUser = $user->fetch('', $login, '', 1, ($entity > 0 ? $entity : -1));
|
$resultFetchUser = $user->fetch('', $login, '', 1, ($entity > 0 ? $entity : -1));
|
||||||
|
if ($resultFetchUser <= 0 || ($user->flagdelsessionsbefore && !empty($_SESSION["dol_logindate"]) && $user->flagdelsessionsbefore > $_SESSION["dol_logindate"])) {
|
||||||
if ($resultFetchUser <= 0) {
|
if ($resultFetchUser <= 0) {
|
||||||
// Account has been removed after login
|
// Account has been removed after login
|
||||||
dol_syslog("Can't load user even if session logged. _SESSION['dol_login']=".$login, LOG_WARNING);
|
dol_syslog("Can't load user even if session logged. _SESSION['dol_login']=".$login, LOG_WARNING);
|
||||||
|
} else {
|
||||||
|
// Session is no more valid
|
||||||
|
dol_syslog("The user has a date for session invalidation = ".$user->flagdelsessionsbefore." and a session date = ".$_SESSION["dol_logindate"].". We must invalidate its sessions.");
|
||||||
|
}
|
||||||
session_destroy();
|
session_destroy();
|
||||||
session_set_cookie_params(0, '/', null, (empty($dolibarr_main_force_https) ? false : true), true); // Add tag secure and httponly on session cookie
|
session_set_cookie_params(0, '/', null, (empty($dolibarr_main_force_https) ? false : true), true); // Add tag secure and httponly on session cookie
|
||||||
session_name($sessionname);
|
session_name($sessionname);
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
if ($resultFetchUser == 0) {
|
if ($resultFetchUser == 0) {
|
||||||
// Load translation files required by page
|
|
||||||
$langs->loadLangs(array('main', 'errors'));
|
$langs->loadLangs(array('main', 'errors'));
|
||||||
|
|
||||||
$_SESSION["dol_loginmesg"] = $langs->transnoentitiesnoconv("ErrorCantLoadUserFromDolibarrDatabase", $login);
|
$_SESSION["dol_loginmesg"] = $langs->transnoentitiesnoconv("ErrorCantLoadUserFromDolibarrDatabase", $login);
|
||||||
|
|
||||||
$user->trigger_mesg = 'ErrorCantLoadUserFromDolibarrDatabase - login='.$login;
|
$user->trigger_mesg = 'ErrorCantLoadUserFromDolibarrDatabase - login='.$login;
|
||||||
}
|
} elseif ($resultFetchUser < 0) {
|
||||||
if ($resultFetchUser < 0) {
|
|
||||||
$_SESSION["dol_loginmesg"] = $user->error;
|
$_SESSION["dol_loginmesg"] = $user->error;
|
||||||
|
|
||||||
$user->trigger_mesg = $user->error;
|
$user->trigger_mesg = $user->error;
|
||||||
|
} else {
|
||||||
|
$langs->loadLangs(array('main', 'errors'));
|
||||||
|
|
||||||
|
$_SESSION["dol_loginmesg"] = $langs->transnoentitiesnoconv("ErrorSessionInvalidatedAfterPasswordChange");
|
||||||
|
|
||||||
|
$user->trigger_mesg = 'ErrorUserSessionWasInvalidated - login='.$login;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call trigger
|
// Call trigger
|
||||||
|
|||||||
@ -521,6 +521,13 @@ if (empty($reshook)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$error) {
|
if (!$error) {
|
||||||
|
$passwordismodified = 0;
|
||||||
|
if (!empty($object->pass)) {
|
||||||
|
if ($object->pass != $object->pass_indatabase && !dol_verifyHash($object->pass, $object->pass_indatabase_crypted)) {
|
||||||
|
$passwordismodified = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$ret = $object->update($user); // This may include call to setPassword if password has changed
|
$ret = $object->update($user); // This may include call to setPassword if password has changed
|
||||||
if ($ret < 0) {
|
if ($ret < 0) {
|
||||||
$error++;
|
$error++;
|
||||||
@ -615,6 +622,13 @@ if (empty($reshook)) {
|
|||||||
$langs->load("errors");
|
$langs->load("errors");
|
||||||
setEventMessages($langs->transnoentitiesnoconv("WarningYourLoginWasModifiedPleaseLogin"), null, 'warnings');
|
setEventMessages($langs->transnoentitiesnoconv("WarningYourLoginWasModifiedPleaseLogin"), null, 'warnings');
|
||||||
}
|
}
|
||||||
|
if ($passwordismodified && $object->login == $user->login) { // Current user has changed its password
|
||||||
|
$error++;
|
||||||
|
$langs->load("errors");
|
||||||
|
setEventMessages($langs->transnoentitiesnoconv("WarningYourPasswordWasModifiedPleaseLogin"), null, 'warnings');
|
||||||
|
header("Location: ".DOL_URL_ROOT.'/user/card.php?id='.$object->id);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$db->rollback();
|
$db->rollback();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -276,6 +276,7 @@ class User extends CommonObject
|
|||||||
|
|
||||||
public $datelastlogin;
|
public $datelastlogin;
|
||||||
public $datepreviouslogin;
|
public $datepreviouslogin;
|
||||||
|
public $flagdelsessionsbefore;
|
||||||
public $iplastlogin;
|
public $iplastlogin;
|
||||||
public $ippreviouslogin;
|
public $ippreviouslogin;
|
||||||
public $datestartvalidity;
|
public $datestartvalidity;
|
||||||
@ -441,6 +442,7 @@ class User extends CommonObject
|
|||||||
$sql .= " u.tms as datem,";
|
$sql .= " u.tms as datem,";
|
||||||
$sql .= " u.datelastlogin as datel,";
|
$sql .= " u.datelastlogin as datel,";
|
||||||
$sql .= " u.datepreviouslogin as datep,";
|
$sql .= " u.datepreviouslogin as datep,";
|
||||||
|
$sql .= " u.flagdelsessionsbefore,";
|
||||||
$sql .= " u.iplastlogin,";
|
$sql .= " u.iplastlogin,";
|
||||||
$sql .= " u.ippreviouslogin,";
|
$sql .= " u.ippreviouslogin,";
|
||||||
$sql .= " u.datelastpassvalidation,";
|
$sql .= " u.datelastpassvalidation,";
|
||||||
@ -575,6 +577,7 @@ class User extends CommonObject
|
|||||||
$this->datem = $this->db->jdate($obj->datem);
|
$this->datem = $this->db->jdate($obj->datem);
|
||||||
$this->datelastlogin = $this->db->jdate($obj->datel);
|
$this->datelastlogin = $this->db->jdate($obj->datel);
|
||||||
$this->datepreviouslogin = $this->db->jdate($obj->datep);
|
$this->datepreviouslogin = $this->db->jdate($obj->datep);
|
||||||
|
$this->flagdelsessionsbefore = $this->db->jdate($obj->flagdelsessionsbefore, 'gmt');
|
||||||
$this->iplastlogin = $obj->iplastlogin;
|
$this->iplastlogin = $obj->iplastlogin;
|
||||||
$this->ippreviouslogin = $obj->ippreviouslogin;
|
$this->ippreviouslogin = $obj->ippreviouslogin;
|
||||||
$this->datestartvalidity = $this->db->jdate($obj->datestartvalidity);
|
$this->datestartvalidity = $this->db->jdate($obj->datestartvalidity);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user