40 global $db, $conf, $langs;
43 $entity = $entitytotest;
44 if (isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
50 if (!empty($usertotest)) {
51 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
52 dol_syslog(
"functions_dolibarr::check_user_password_dolibarr usertotest=".$usertotest.
" passwordtotest=".preg_replace(
'/./',
'*', $passwordtotest).
" entitytotest=".$entitytotest);
55 $table = MAIN_DB_PREFIX.
"user";
56 $usernamecol1 =
'login';
57 $usernamecol2 =
'email';
58 $entitycol =
'entity';
60 $sql =
"SELECT rowid, login, entity, pass, pass_crypted, datestartvalidity, dateendvalidity, flagdelsessionsbefore";
61 $sql .=
" FROM ".$table;
62 $sql .=
" WHERE (".$usernamecol1.
" = '".$db->escape($usertotest).
"'";
63 if (preg_match(
'/@/', $usertotest)) {
64 $sql .=
" OR ".$usernamecol2.
" = '".$db->escape($usertotest).
"'";
66 $sql .=
") AND ".$entitycol.
" IN (0,".($entity ? ((int) $entity) : 1).
")";
67 $sql .=
" AND statut = 1";
70 $sql .=
" ORDER BY entity DESC";
74 $resql = $db->query($sql);
76 $obj = $db->fetch_object($resql);
78 $passclear = $obj->pass;
79 $passcrypted = $obj->pass_crypted;
80 $passtyped = $passwordtotest;
86 if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
87 $cryptType = $conf->global->DATABASE_PWD_ENCRYPTED;
91 if (!in_array($cryptType, array(
'auto'))) {
95 if ($cryptType ==
'auto') {
96 if ($passcrypted &&
dol_verifyHash($passtyped, $passcrypted,
'0')) {
98 dol_syslog(
"functions_dolibarr::check_user_password_dolibarr Authentification ok - hash ".$cryptType.
" of pass is ok");
104 if ((!$passcrypted || $passtyped)
105 && ($passclear && ($passtyped == $passclear))) {
107 dol_syslog(
"functions_dolibarr::check_user_password_dolibarr Authentification ok - found old pass in database", LOG_WARNING);
113 $login = $obj->login;
115 dol_syslog(
"functions_dolibarr::check_user_password_dolibarr Authentication KO bad password for '".$usertotest.
"', cryptType=".$cryptType, LOG_NOTICE);
119 $langs->loadLangs(array(
'main',
'errors'));
121 $_SESSION[
"dol_loginmesg"] = $langs->transnoentitiesnoconv(
"ErrorBadLoginPassword");
125 if ($passok && isModEnabled(
'multicompany')) {
129 !isModEnabled(
'multicompany');
131 $ret = $mc->checkRight($obj->rowid, $entitytotest);
133 dol_syslog(
"functions_dolibarr::check_user_password_dolibarr Authentication KO entity '".$entitytotest.
"' not allowed for user '".$obj->rowid.
"'", LOG_NOTICE);
136 if ($mc->db->lasterror()) {
137 $_SESSION[
"dol_loginmesg"] = $mc->db->lasterror();
143 dol_syslog(
"functions_dolibarr::check_user_password_dolibarr Authentication KO user not found for '".$usertotest.
"'", LOG_NOTICE);
147 $langs->loadLangs(array(
'main',
'errors'));
149 $_SESSION[
"dol_loginmesg"] = $langs->transnoentitiesnoconv(
"ErrorBadLoginPassword");
152 dol_syslog(
"functions_dolibarr::check_user_password_dolibarr Authentication KO db error for '".$usertotest.
"' error=".$db->lasterror(), LOG_ERR);
154 $_SESSION[
"dol_loginmesg"] = $db->lasterror();
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,...