39 global $db, $conf, $langs;
42 $entity = $entitytotest;
43 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
49 if (!empty($usertotest)) {
50 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
51 dol_syslog(
"functions_dolibarr::check_user_password_dolibarr usertotest=".$usertotest.
" passwordtotest=".preg_replace(
'/./',
'*', $passwordtotest).
" entitytotest=".$entitytotest);
54 $table = MAIN_DB_PREFIX.
"user";
55 $usernamecol1 =
'login';
56 $usernamecol2 =
'email';
57 $entitycol =
'entity';
59 $sql =
"SELECT rowid, login, entity, pass, pass_crypted, datestartvalidity, dateendvalidity";
60 $sql .=
" FROM ".$table;
61 $sql .=
" WHERE (".$usernamecol1.
" = '".$db->escape($usertotest).
"'";
62 if (preg_match(
'/@/', $usertotest)) {
63 $sql .=
" OR ".$usernamecol2.
" = '".$db->escape($usertotest).
"'";
65 $sql .=
") AND ".$entitycol.
" IN (0,".($entity ? ((int) $entity) : 1).
")";
66 $sql .=
" AND statut = 1";
70 $sql .=
" ORDER BY entity DESC";
74 $obj = $db->fetch_object(
$resql);
77 if ($obj->datestartvalidity && $db->jdate($obj->datestartvalidity) > $now) {
79 $langs->loadLangs(array(
'main',
'errors'));
80 $_SESSION[
"dol_loginmesg"] = $langs->transnoentitiesnoconv(
"ErrorLoginDateValidity");
81 return '--bad-login-validity--';
83 if ($obj->dateendvalidity && $db->jdate($obj->dateendvalidity) <
dol_get_first_hour($now)) {
85 $langs->loadLangs(array(
'main',
'errors'));
86 $_SESSION[
"dol_loginmesg"] = $langs->transnoentitiesnoconv(
"ErrorLoginDateValidity");
87 return '--bad-login-validity--';
90 $passclear = $obj->pass;
91 $passcrypted = $obj->pass_crypted;
92 $passtyped = $passwordtotest;
98 if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
99 $cryptType = $conf->global->DATABASE_PWD_ENCRYPTED;
103 if (!in_array($cryptType, array(
'auto'))) {
107 if ($cryptType ==
'auto') {
108 if ($passcrypted &&
dol_verifyHash($passtyped, $passcrypted,
'0')) {
110 dol_syslog(
"functions_dolibarr::check_user_password_dolibarr Authentification ok - hash ".$cryptType.
" of pass is ok");
116 if ((!$passcrypted || $passtyped)
117 && ($passclear && ($passtyped == $passclear))) {
119 dol_syslog(
"functions_dolibarr::check_user_password_dolibarr Authentification ok - found pass in database");
125 $login = $obj->login;
127 dol_syslog(
"functions_dolibarr::check_user_password_dolibarr Authentication KO bad password for '".$usertotest.
"', cryptType=".$cryptType, LOG_NOTICE);
131 $langs->loadLangs(array(
'main',
'errors'));
133 $_SESSION[
"dol_loginmesg"] = $langs->transnoentitiesnoconv(
"ErrorBadLoginPassword");
143 $ret = $mc->checkRight($obj->rowid, $entitytotest);
145 dol_syslog(
"functions_dolibarr::check_user_password_dolibarr Authentication KO entity '".$entitytotest.
"' not allowed for user '".$obj->rowid.
"'", LOG_NOTICE);
148 if ($mc->db->lasterror()) {
149 $_SESSION[
"dol_loginmesg"] = $mc->db->lasterror();
155 dol_syslog(
"functions_dolibarr::check_user_password_dolibarr Authentication KO user not found for '".$usertotest.
"'", LOG_NOTICE);
159 $langs->loadLangs(array(
'main',
'errors'));
161 $_SESSION[
"dol_loginmesg"] = $langs->transnoentitiesnoconv(
"ErrorBadLoginPassword");
164 dol_syslog(
"functions_dolibarr::check_user_password_dolibarr Authentication KO db error for '".$usertotest.
"' error=".$db->lasterror(), LOG_ERR);
166 $_SESSION[
"dol_loginmesg"] = $db->lasterror();
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_get_first_hour($date, $gm='tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
dol_now($mode='auto')
Return date for now.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
check_user_password_dolibarr($usertotest, $passwordtotest, $entitytotest=1)
Check validity of user/password/entity If test is ko, reason must be filled into $_SESSION["dol_login...
dol_verifyHash($chain, $hash, $type='0')
Compute a hash and compare it to the given one For backward compatibility reasons,...