40 global $db, $conf, $langs;
43 $entity = $entitytotest;
44 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'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);
59 $sql =
"SELECT COUNT(e.rowid) as nbevent";
60 $sql .=
" FROM ".MAIN_DB_PREFIX.
"events as e";
61 $sql .=
" WHERE e.type = 'USER_LOGIN_FAILED'";
62 $sql .=
" AND e.ip = '".$db->escape($userremoteip).
"'";
63 $sql .=
" AND e.dateevent > '".$db->idate($dateverificationauth).
"'";
64 $resql = $db->query($sql);
66 $obj = $db->fetch_object($resql);
68 $nbevents = $obj->nbevent;
72 if ($nbevents <=
getDolGlobalInt(
"MAIN_SECURITY_MAX_NUMBER_FAILED_AUTH", 100)) {
74 $table = MAIN_DB_PREFIX.
"user";
75 $usernamecol1 =
'login';
76 $usernamecol2 =
'email';
77 $entitycol =
'entity';
79 $sql =
"SELECT rowid, login, entity, pass, pass_crypted, datestartvalidity, dateendvalidity, flagdelsessionsbefore";
80 $sql .=
" FROM ".$table;
81 $sql .=
" WHERE (".$usernamecol1.
" = '".$db->escape($usertotest).
"'";
82 if (preg_match(
'/@/', $usertotest)) {
83 $sql .=
" OR ".$usernamecol2.
" = '".$db->escape($usertotest).
"'";
85 $sql .=
") AND ".$entitycol.
" IN (0,".($entity ? ((int) $entity) : 1).
")";
86 $sql .=
" AND statut = 1";
89 $sql .=
" ORDER BY entity DESC";
93 $resql = $db->query($sql);
95 $obj = $db->fetch_object($resql);
97 $passclear = $obj->pass;
98 $passcrypted = $obj->pass_crypted;
99 $passtyped = $passwordtotest;
106 $cryptType = $conf->global->DATABASE_PWD_ENCRYPTED;
110 if (!in_array($cryptType, array(
'auto'))) {
114 if ($cryptType ==
'auto') {
115 if ($passcrypted &&
dol_verifyHash($passtyped, $passcrypted,
'0')) {
117 dol_syslog(
"functions_dolibarr::check_user_password_dolibarr Authentification ok - hash ".$cryptType.
" of pass is ok");
123 if ((!$passcrypted || $passtyped)
124 && ($passclear && ($passtyped == $passclear))) {
126 dol_syslog(
"functions_dolibarr::check_user_password_dolibarr Authentification ok - found old pass in database", LOG_WARNING);
132 $login = $obj->login;
134 dol_syslog(
"functions_dolibarr::check_user_password_dolibarr Authentication KO bad password for '".$usertotest.
"', cryptType=".$cryptType, LOG_NOTICE);
138 $langs->loadLangs(array(
'main',
'errors'));
140 $_SESSION[
"dol_loginmesg"] = $langs->transnoentitiesnoconv(
"ErrorBadLoginPassword");
144 if ($passok && isModEnabled(
'multicompany')) {
148 !isModEnabled(
'multicompany');
150 $ret = $mc->checkRight($obj->rowid, $entitytotest);
152 dol_syslog(
"functions_dolibarr::check_user_password_dolibarr Authentication KO entity '".$entitytotest.
"' not allowed for user '".$obj->rowid.
"'", LOG_NOTICE);
155 if ($mc->db->lasterror()) {
156 $_SESSION[
"dol_loginmesg"] = $mc->db->lasterror();
162 dol_syslog(
"functions_dolibarr::check_user_password_dolibarr Authentication KO user not found for '".$usertotest.
"'", LOG_NOTICE);
166 $langs->loadLangs(array(
'main',
'errors'));
168 $_SESSION[
"dol_loginmesg"] = $langs->transnoentitiesnoconv(
"ErrorBadLoginPassword");
171 dol_syslog(
"functions_dolibarr::check_user_password_dolibarr Authentication KO db error for '".$usertotest.
"' error=".$db->lasterror(), LOG_ERR);
173 $_SESSION[
"dol_loginmesg"] = $db->lasterror();
176 dol_syslog(
"functions_dolibarr::check_user_password_dolibarr Authentication KO Too many attempts", LOG_NOTICE);
179 $langs->loadLangs(array(
'main',
'errors'));
180 $_SESSION[
"dol_loginmesg"] = $langs->transnoentitiesnoconv(
"ErrorTooManyAttempts");
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,...