40 if ($mode ==
'user') {
41 $t = getenv(
'APACHE_RUN_USER');
43 if ($mode ==
'group') {
44 $t = getenv(
'APACHE_RUN_GROUP');
64 if ($entitytotest ==
'') {
68 dol_syslog(
"checkLoginPassEntity usertotest=".$usertotest.
" entitytotest=".$entitytotest.
" authmode=".implode(
',', $authmode));
74 foreach ($authmode as $mode) {
75 if ($test && $mode && !$login) {
78 $authfile =
'functions_'.$mode.
'.php';
81 $dirlogin = array_merge(array(
"/core/login"), (array)
$conf->modules_parts[
'login']);
82 foreach ($dirlogin as $reldir) {
87 $tmpnewauthfile = $newdir.(preg_match(
'/\/$/', $newdir) ?
'' :
'/').$authfile;
88 if (is_file($tmpnewauthfile)) {
89 $fullauthfile = $tmpnewauthfile;
95 $result = include_once $fullauthfile;
97 if ($fullauthfile && $result) {
99 $function =
'check_user_password_'.$mode;
100 $login = call_user_func($function, $usertotest, $passwordtotest, $entitytotest,
$context);
101 if ($login && $login !=
'--bad-login-validity--') {
104 $conf->authmode = $mode;
111 dol_syslog(
"Authentication KO - failed to load file '".$authfile.
"'", LOG_ERR);
114 $langs->loadLangs(array(
'other',
'main',
'errors'));
116 $_SESSION[
"dol_loginmesg"] = (empty($_SESSION[
"dol_loginmesg"]) ?
'' : $_SESSION[
"dol_loginmesg"].
', ').$langs->transnoentitiesnoconv(
"ErrorFailedToLoadLoginFileForMode", $mode);
126if (!function_exists(
'dol_loginfunction')) {
138 global $dolibarr_main_demo, $dolibarr_main_force_https;
139 global $db, $hookmanager;
141 $langs->loadLangs(array(
"main",
"other",
"help",
"admin"));
144 $hookmanager->initHooks(array(
'mainloginpage'));
146 $main_authentication =
$conf->file->main_authentication;
148 $session_name = session_name();
150 $dol_url_root = DOL_URL_ROOT;
153 $appli = constant(
'DOL_APPLICATION_TITLE');
154 $title = $appli.(getDolGlobalString(
'MAIN_OPTIMIZEFORTEXTBROWSER') ?
'' :
' '.constant(
'DOL_VERSION'));
157 if ($customapplication) {
158 if (preg_match(
'/^\+/', $customapplication)) {
159 $title .= $customapplication;
161 $title = $customapplication;
164 $titletruedolibarrversion = constant(
'DOL_VERSION');
186 if (!empty(
$conf->modules_parts[
'tpl'])) {
187 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array(
'/core/tpl/'));
188 foreach ($dirtpls as $reldir) {
190 if (file_exists($tmp)) {
191 $template_dir = preg_replace(
'/login\.tpl\.php$/',
'', $tmp);
196 $template_dir = DOL_DOCUMENT_ROOT.
"/core/tpl/";
201 $prefix = dol_getprefix(
'');
202 $sessiontimeout =
'DOLSESSTIMEOUT_'.$prefix;
208 if (
GETPOST(
'urlfrom',
'alpha')) {
209 $_SESSION[
"urlfrom"] =
GETPOST(
'urlfrom',
'alpha');
211 unset($_SESSION[
"urlfrom"]);
214 if (!
GETPOST(
"username",
'alpha')) {
215 $focus_element =
'username';
217 $focus_element =
'password';
222 if (!empty($dolibarr_main_demo)) {
223 $tab = explode(
',', $dolibarr_main_demo);
224 $demologin = $tab[0];
225 $demopassword = $tab[1];
229 $parameters = array(
'entity' =>
GETPOSTINT(
'entity'),
'switchentity' =>
GETPOSTINT(
'switchentity'));
230 $reshook = $hookmanager->executeHooks(
'getLoginPageOptions', $parameters);
231 $morelogincontent = $hookmanager->resPrint;
234 $parameters = array(
'entity' =>
GETPOSTINT(
'entity'),
'switchentity' =>
GETPOSTINT(
'switchentity'));
235 $reshook = $hookmanager->executeHooks(
'getLoginPageExtraOptions', $parameters);
236 $moreloginextracontent = $hookmanager->resPrint;
239 $parameters = array(
'entity' =>
GETPOSTINT(
'entity'),
'switchentity' =>
GETPOSTINT(
'switchentity'));
240 $reshook = $hookmanager->executeHooks(
'redirectAfterConnection', $parameters);
241 $php_self = $hookmanager->resPrint;
244 $login = (!empty($hookmanager->resArray[
'username']) ? $hookmanager->resArray[
'username'] : (
GETPOST(
"username",
"alpha") ?
GETPOST(
"username",
"alpha") : $demologin));
245 $password = $demopassword;
249 $urllogo = DOL_URL_ROOT.
'/theme/common/login_logo.png';
251 if (!empty(
$mysoc->logo_small) && is_readable(
$conf->mycompany->dir_output.
'/logos/thumbs/'.
$mysoc->logo_small)) {
252 $urllogo = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.
$mysoc->logo_small);
253 } elseif (!empty(
$mysoc->logo) && is_readable(
$conf->mycompany->dir_output.
'/logos/'.
$mysoc->logo)) {
254 $urllogo = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/'.
$mysoc->logo);
256 } elseif (!empty(
$mysoc->logo_squarred_small) && is_readable(
$conf->mycompany->dir_output.
'/logos/thumbs/'.
$mysoc->logo_squarred_small)) {
257 $urllogo = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.
$mysoc->logo_squarred_small);
258 } elseif (is_readable(DOL_DOCUMENT_ROOT.
'/theme/dolibarr_logo.svg')) {
259 $urllogo = DOL_URL_ROOT.
'/theme/dolibarr_logo.svg';
284 $substitutionarray = getCommonSubstitutionArray($langs);
295 $dol_loginmesg = (!empty($_SESSION[
"dol_loginmesg"]) ? $_SESSION[
"dol_loginmesg"] :
'');
297 $favicon = DOL_URL_ROOT.
'/theme/dolibarr_256x256_color.png';
298 if (!empty(
$mysoc->logo_squarred_mini)) {
299 $favicon = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.
$mysoc->logo_squarred_mini);
305 $jquerytheme =
'base';
311 $dol_hide_topmenu =
GETPOSTINT(
'dol_hide_topmenu');
312 $dol_hide_leftmenu =
GETPOSTINT(
'dol_hide_leftmenu');
313 $dol_optimize_smallscreen =
GETPOSTINT(
'dol_optimize_smallscreen');
314 $dol_no_mouse_hover =
GETPOSTINT(
'dol_no_mouse_hover');
315 $dol_use_jmobile =
GETPOSTINT(
'dol_use_jmobile');
318 include $template_dir.
'login.tpl.php';
323 $_SESSION[
"dol_loginmesg"] =
'';
358 $salt .= chr(mt_rand(64, 126));
361 $result = $saltprefix.$salt.$saltsuffix;
374 dol_syslog(
"encodedecode_dbpassconf level=".$level, LOG_DEBUG);
377 $passwd_crypted =
'';
379 if ($fp = fopen(DOL_DOCUMENT_ROOT.
'/conf/conf.php',
'r')) {
381 $buffer = fgets($fp, 4096);
387 if (preg_match(
'/^[^#]*dolibarr_main_db_encrypted_pass[\s]*=[\s]*(.*)/i', $buffer, $reg)) {
388 $val = trim($reg[1]);
389 $val = preg_replace(
'/^["\']/',
'', $val);
390 $val = preg_replace(
'/["\'][\s;]*$/',
'', $val);
392 $passwd_crypted = $val;
399 } elseif (preg_match(
'/^[^#]*dolibarr_main_db_pass[\s]*=[\s]*(.*)/i', $buffer, $reg)) {
400 $val = trim($reg[1]);
401 $val = preg_replace(
'/^["\']/',
'', $val);
402 $val = preg_replace(
'/["\'][\s;]*$/',
'', $val);
403 if (preg_match(
'/crypted:/i', $buffer)) {
406 $val = preg_replace(
'/crypted:/i',
'', $val);
407 $passwd_crypted = $val;
410 } elseif (preg_match(
'/^dolcrypt:([^:]+):(.*)$/i', $val, $reg)) {
414 $passwd_crypted = $reg[1].
':'.$reg[2];
424 $passwd_crypted = preg_replace(
'/^dolcrypt:/',
'',
dolEncrypt($val));
433 $config .=
'$dolibarr_main_db_pass=\''.$passwd.
'\';
'."\n";
436 $config .= '$dolibarr_main_db_pass=\
''.$mode.$passwd_crypted.
'\';
'."\n";
439 //print 'passwd =
'.$passwd.' - passwd_crypted =
'.$passwd_crypted;
447 // Write new conf file
448 $file = DOL_DOCUMENT_ROOT.'/
conf/
conf.php
';
449 if ($fp = @fopen($file, 'w
')) {
450 fwrite($fp, $config);
455 // It's config file, so we
set read permission
for creator only.
461 dol_syslog(
"encodedecode_dbpassconf Failed to open conf.php file for writing", LOG_WARNING);
465 dol_syslog(
"encodedecode_dbpassconf Failed to read conf.php", LOG_ERR);
485 return empty(
$conf->file->restrict_password_generation_none) ? 0 : 1;
514 global $db,
$conf, $langs, $user;
516 $generated_password =
'';
519 $lowercase =
"qwertyuiopasdfghjklzxcvbnm";
520 $uppercase =
"ASDFGHJKLZXCVBNMQWERTYUIOP";
521 $numbers =
"1234567890";
523 $nbofchar = round($length / 3);
524 $nbofcharlast = ($length - 2 * $nbofchar);
526 if (function_exists(
'random_int')) {
527 $max = strlen($lowercase) - 1;
528 for ($x = 0; $x < $nbofchar; $x++) {
529 $tmp = random_int(0, $max);
530 $randomCode .= $lowercase[$tmp];
532 $max = strlen($uppercase) - 1;
533 for ($x = 0; $x < $nbofchar; $x++) {
534 $tmp = random_int(0, $max);
535 $randomCode .= $uppercase[$tmp];
537 $max = strlen($numbers) - 1;
538 for ($x = 0; $x < $nbofcharlast; $x++) {
539 $tmp = random_int(0, $max);
540 $randomCode .= $numbers[$tmp];
544 $max = strlen($lowercase) - 1;
545 for ($x = 0; $x < $nbofchar; $x++) {
546 $tmp = mt_rand(0, $max);
547 $randomCode .= $lowercase[$tmp];
549 $max = strlen($uppercase) - 1;
550 for ($x = 0; $x < $nbofchar; $x++) {
551 $tmp = mt_rand(0, $max);
552 $randomCode .= $uppercase[$tmp];
554 $max = strlen($numbers) - 1;
555 for ($x = 0; $x < $nbofcharlast; $x++) {
556 $tmp = mt_rand(0, $max);
557 $randomCode .= $numbers[$tmp];
562 $passwordArray = str_split($randomCode);
563 for ($i = count($passwordArray) - 1; $i > 0; $i--) {
564 $j = random_int(0, $i);
565 $tmp = $passwordArray[$i];
566 $passwordArray[$i] = $passwordArray[$j];
567 $passwordArray[$j] = $tmp;
569 $generated_password = implode(
'', $passwordArray);
571 require_once DOL_DOCUMENT_ROOT.
"/core/modules/security/generate/modules_genpassword.php";
577 dol_syslog(
"getRandomPassword: generator class for USER_PASSWORD_GENERATED='".
getDolGlobalString(
'USER_PASSWORD_GENERATED').
"' not found, falling back to standard", LOG_WARNING);
581 '@phan-var-force ModeleGenPassword $genhandler';
582 $generated_password = $genhandler->getNewGeneratedPassword();
588 if (is_array($replaceambiguouschars) && count($replaceambiguouschars) > 0) {
590 $max = strlen($numbers) - 1;
591 if (function_exists(
'random_int')) {
592 $tmp = random_int(0, $max);
593 $generated_password = str_replace($replaceambiguouschars, $numbers[$tmp], $generated_password);
595 $tmp = mt_rand(0, $max);
596 $generated_password = str_replace($replaceambiguouschars, $numbers[$tmp], $generated_password);
600 return $generated_password;
618 if (!empty(
$conf->use_javascript_ajax)) {
619 $out .=
"\n".
'<!-- Js code to suggest a security key -->';
620 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">';
621 $out .=
'jQuery(document).ready(function () {
622 jQuery(\'#'.dol_escape_js($htmlnameofbutton).
'\').click(
function() {
623 var currenttoken = jQuery(
"meta[name=anti-csrf-currenttoken]").attr(
"content");
624 console.log(\
'dolJSToSetRandomPassword: We click on the button '.
dol_escape_js($htmlnameofbutton).
' to suggest a key. anti-csrf-currenttoken is \'+currenttoken+\'. We will fill '.
dol_escape_js($htmlname).
'\');
625 jQuery.get(
"'.DOL_URL_ROOT.'/core/ajax/security.php", {
626 action: \
'getrandompassword\',
627 generic: '.($generic ?
'1' :
'0').
',
631 if (jQuery(\'input#'.
dol_escape_js($htmlname).
'\').attr(
"type") ==
"password") {
632 jQuery(\
'input#'.
dol_escape_js($htmlname).
'\').attr(
"type",
"text");
651function showEyeForField($htmlname, $htmlnameofinput)
653 return '<!-- code to manage the eye hide/show -->
654<span
id=
"'.$htmlname.'" tabindex=
"-1"><span
class=
"fa fa-eye"></span></span>
655<script nonce=
"'.getNonce().'">
656 $(document).ready(
function () {
657 $(\
'#'.$htmlname.
'\').on(\
'click\', function (e) {
659 if (event.detail === 0) return false; // Ignore keyboard "clicks"
660 console.log("We click on '.$htmlname.
'");
661 const $passwordInput = $(\'#'.$htmlnameofinput.
'\');
663 if ($passwordInput.is(\
'[type=password]\')) {
664 $passwordInput.attr(\'type\', \'text\');
665 jQuery(\'#'.$htmlname.
' .fa-eye\').attr(\'class\', \'fa fa-eye-slash\');
667 $passwordInput.attr(\'type\', \'password\');
668 jQuery(\'#'.$htmlname.
' .fa-eye-slash\').attr(\'class\', \'fa fa-eye\');
671 return false; // This prevents the click from reloading the page
697 $alphabet =
'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
700 $nboctets = strlen($bin);
701 for ($i = 0; $i < $nboctets; $i++) {
702 $bits .= str_pad(decbin(ord($bin[$i])), 8,
'0', STR_PAD_LEFT);
704 foreach (str_split($bits, 5) as $chunk) {
705 $out .= $alphabet[bindec(str_pad($chunk, 5,
'0', STR_PAD_RIGHT))];
718 $alphabet =
'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
719 $clean = preg_replace(
'/[^A-Z2-7]/',
'',
dol_strtoupper($base32));
723 for ($i = 0; $i < $nbchars; $i++) {
724 $bits .= str_pad(decbin((
int) strpos($alphabet, $clean[$i])), 5,
'0', STR_PAD_LEFT);
726 foreach (str_split($bits, 8) as $chunk) {
728 $out .= chr(bindec($chunk));
746 $offset = ord($hash[strlen($hash) - 1]) & 0x0F;
747 $value = unpack(
'N', substr($hash, $offset, 4))[1] & 0x7FFFFFFF;
748 return str_pad((
string) ($value % (10 ** $digits)), $digits,
'0', STR_PAD_LEFT);
763function dolTotpCheckCode($base32secret, $code, $timestamp = 0, $period = 30, $digits = 6, $drift = 1)
765 if (!is_string($code) && !is_int($code)) {
768 $code = preg_replace(
'/[^0-9]/',
'', (
string) $code);
769 if (
dol_strlen($code) != $digits || empty($base32secret)) {
772 if (empty($timestamp)) {
775 $currentstep = (int) floor($timestamp / $period);
776 for ($i = -$drift; $i <= $drift; $i++) {
777 if (hash_equals(
dolTotpGetCode($base32secret, $currentstep + $i, $digits), $code)) {
778 return $currentstep + $i;
794function dolTotpGetUri($login, $base32secret, $issuer =
'', $digits = 6, $period = 30)
798 if (empty($issuer)) {
799 $issuer = (empty(
$mysoc->name) ?
'Dolibarr' :
$mysoc->name);
801 $label = rawurlencode($issuer).
':'.rawurlencode($login);
802 $params =
'secret='.rawurlencode($base32secret).
'&issuer='.rawurlencode($issuer).
'&algorithm=SHA1&digits='.((int) $digits).
'&period='.((int) $period);
804 return 'otpauth://totp/'.$label.
'?'.$params;
817 $sql =
"SELECT rowid, tokenstring, state, datec, lastaccess FROM ".$db->prefix().
"oauth_token";
818 $sql .=
" WHERE service = 'dolibarr_totp' AND fk_user = ".((int) $fk_user);
820 $resql = $db->query($sql);
822 dol_syslog(
"dolTotpGetEnrollment ".$db->lasterror(), LOG_ERR);
825 $num = $db->num_rows($resql);
826 $obj = ($num > 0 ? $db->fetch_object($resql) :
null);
832 dol_syslog(
"dolTotpGetEnrollment: row of user ".((
int) $fk_user).
" can't be fetched", LOG_ERR);
836 $data = json_decode((
string) $obj->tokenstring,
true);
837 if (!is_array($data) || empty($data[
'secret'])) {
838 dol_syslog(
"dolTotpGetEnrollment: unreadable tokenstring for user ".((
int) $fk_user), LOG_ERR);
842 return array(
'rowid' => (
int) $obj->rowid,
'secret' =>
dolDecrypt($data[
'secret']),
'laststep' => (
int) $obj->state,
'datec' => $db->jdate($obj->datec),
'lastaccess' => $db->jdate($obj->lastaccess));
858 if (strpos($encryptedsecret,
'dolcrypt:') !== 0) {
859 dol_syslog(
"dolTotpSaveEnrollment: the instance has no encryption key or no openssl, the secret would be stored in clear", LOG_ERR);
862 $tokenstring = json_encode(array(
'secret' => $encryptedsecret));
865 $sql =
"INSERT INTO ".$db->prefix().
"oauth_token(service, tokenstring, state, fk_user, entity, datec, lastaccess)";
866 $sql .=
" VALUES ('dolibarr_totp', '".$db->escape($tokenstring).
"', '".$db->escape(
dolTotpFormatStep($laststep)).
"', ".((int) $fk_user).
", ".((int) $entity).
", '".$db->idate($now).
"', '".$db->idate($now).
"')";
868 if (!$db->query($sql)) {
869 dol_syslog(
"dolTotpSaveEnrollment ".$db->lasterror(), LOG_ERR);
889 $sql =
"UPDATE ".$db->prefix().
"oauth_token SET state = '".$db->escape($newstate).
"', lastaccess = '".$db->idate(
dol_now()).
"'";
890 $sql .=
" WHERE rowid = ".((int) $rowid).
" AND (state IS NULL OR state = '' OR state < '".$db->escape($newstate).
"')";
892 $resql = $db->query($sql);
894 dol_syslog(
"dolTotpSetLastStep ".$db->lasterror(), LOG_ERR);
897 if ($db->affected_rows($resql) < 1) {
912 return str_pad((
string) ((
int) $timestep), 12,
'0', STR_PAD_LEFT);
924 $sql =
"DELETE FROM ".$db->prefix().
"oauth_token WHERE service = 'dolibarr_totp' AND fk_user = ".((int) $fk_user);
926 if (!$db->query($sql)) {
927 dol_syslog(
"dolTotpDeleteEnrollment ".$db->lasterror(), LOG_ERR);
946 global
$conf, $langs;
948 $tmpuser =
new User($db);
949 if ($tmpuser->fetch(0, $login,
'', 0, ($entity > 0 ? $entity : -1)) <= 0) {
950 $langs->loadLangs(array(
'main',
'errors'));
951 $_SESSION[
"dol_loginmesg"] = $langs->transnoentitiesnoconv(
"ErrorCantLoadUserFromDolibarrDatabase", $login);
955 if ($enrollment ===
null) {
958 if (!is_array($enrollment)) {
959 $langs->load(
"users");
960 $_SESSION[
"dol_loginmesg"] = $langs->transnoentitiesnoconv(
"TOTPUnreadableEnrollment");
964 if (session_status() === PHP_SESSION_ACTIVE && !session_regenerate_id(
true)) {
965 dol_syslog(
"dolTotpStartSecondFactor: session id could not be regenerated", LOG_WARNING);
968 $_SESSION[
'dol_totp_pending'] = array(
'login' => $login,
'entity' => (
int) $entity,
'authmode' => (empty(
$conf->authmode) ?
'' :
$conf->authmode),
'tries' => 0,
'expire' =>
dol_now() + 300);
969 dol_syslog(
"Password accepted for ".$login.
", now waiting for the two-factor authentication code", LOG_NOTICE);
984 global
$conf, $langs;
986 $langs->load(
"users");
988 $pending = empty($_SESSION[
'dol_totp_pending']) ? array() : $_SESSION[
'dol_totp_pending'];
989 if (empty($pending[
'login']) || $pending[
'expire'] <
dol_now()) {
990 unset($_SESSION[
'dol_totp_pending']);
991 $_SESSION[
"dol_loginmesg"] = $langs->transnoentitiesnoconv(
"TOTPLoginExpired");
998 if ($nbfailedauth < 0 || $nbfailedauth >
getDolGlobalInt(
"MAIN_SECURITY_MAX_NUMBER_FAILED_AUTH", 100)) {
999 unset($_SESSION[
'dol_totp_pending']);
1000 dol_syslog(
"Two-factor authentication code refused for ".$pending[
'login'].
": too many failed authentications from ".
getUserRemoteIP(), LOG_WARNING);
1001 $_SESSION[
"dol_loginmesg"] = $langs->transnoentitiesnoconv(
"TOTPBadCode");
1005 $tmpuser =
new User($db);
1006 if ($tmpuser->fetch(0, $pending[
'login'],
'', 0, ($pending[
'entity'] > 0 ? $pending[
'entity'] : -1)) <= 0) {
1007 unset($_SESSION[
'dol_totp_pending']);
1011 if (!is_array($enrollment)) {
1012 unset($_SESSION[
'dol_totp_pending']);
1017 if ($laststep <= 0 || $laststep <= $enrollment[
'laststep']) {
1018 $pending[
'tries'] = (empty($pending[
'tries']) ? 0 : (int) $pending[
'tries']) + 1;
1019 if ($pending[
'tries'] >= 3) {
1020 unset($_SESSION[
'dol_totp_pending']);
1022 $_SESSION[
'dol_totp_pending'] = $pending;
1024 dol_syslog(
"Two-factor authentication code refused for ".$pending[
'login'], LOG_WARNING);
1025 $_SESSION[
"dol_loginmesg"] = $langs->transnoentitiesnoconv(
"TOTPBadCode");
1029 unset($_SESSION[
'dol_totp_pending']);
1031 dol_syslog(
"Two-factor authentication code refused for ".$pending[
'login'].
", its time step could not be recorded", LOG_WARNING);
1032 $_SESSION[
"dol_loginmesg"] = $langs->transnoentitiesnoconv(
"TOTPBadCode");
1035 $conf->authmode = $pending[
'authmode'];
1036 if (session_status() === PHP_SESSION_ACTIVE && !session_regenerate_id(
true)) {
1037 dol_syslog(
"dolTotpCheckPendingLogin: session id could not be regenerated", LOG_WARNING);
1040 return $pending[
'login'];
1052 $sql =
"SELECT COUNT(e.rowid) as nbevent";
1053 $sql .=
" FROM ".$db->prefix().
"events as e";
1054 $sql .=
" WHERE e.type = 'USER_LOGIN_FAILED'";
1056 $sql .=
" AND e.dateevent > '".$db->idate(
dol_now() - 24 * 3600).
"'";
1058 $resql = $db->query($sql);
1060 dol_syslog(
"dolTotpGetNbFailedAuthFromIp ".$db->lasterror(), LOG_ERR);
1063 $obj = $db->fetch_object($resql);
1066 return (empty($obj) ? 0 : (int) $obj->nbevent);
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
static loadAndInstantiate($id, $db, $conf, $langs, $user)
Locate, load and instantiate a password generator/validator model by its id (the value stored in USER...
Class to manage Dolibarr users.
$context
@method int call_trigger(string $triggerName, ?User $user)
dol_now($mode='gmt')
Return date for now.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dolSetCookie(string $cookiename, string $cookievalue, int $expire=-1)
Set a cookie.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_strtoupper($string, $encoding="UTF-8")
Convert a string to upper.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_htmloutput_events($disabledoutputofmessages=0)
Print formatted messages to output (Used to show messages on html output).
conf($dolibarr_main_document_root, $realpathconf=null)
Load conf file (file must exists)
dolTotpSaveEnrollment($db, $fk_user, $secret, $laststep, $entity=1)
Save a TOTP enrollment confirmed by a valid code.
dolTotpCheckPendingLogin($db)
Check the code of the second step of a two-factor authentication.
dolTotpBase32Decode($base32)
Decode a base32 string (alphabet of the RFC 4648).
dolJSToSetRandomPassword($htmlname, $htmlnameofbutton='generate_token', $generic=1)
Output javascript to autoset a generated password using default module into a HTML element.
dolTotpNewSecret($nbbytes=20)
Generate a new secret for a TOTP enrollment (RFC 6238), in the base32 form expected by the authentica...
dolTotpDeleteEnrollment($db, $fk_user)
Delete the TOTP enrollment of a user, who then logs in with the password only again.
dolTotpSetLastStep($db, $rowid, $laststep)
Store the time step of the last code accepted, so the same code can't be played twice.
dolTotpGetUri($login, $base32secret, $issuer='', $digits=6, $period=30)
Build the otpauth:// URI of an enrollment, to be shown as a QR code to the user.
dolTotpFormatStep($timestep)
Format a time step for the 'state' field, at a fixed width so the string comparison done in SQL is a ...
dol_getwebuser($mode)
Return user/group account of web server.
dolTotpGetNbFailedAuthFromIp($db)
Count the failed authentications recorded for the IP of the current request over the last 24 hours.
getPasswordPatternMinLength()
Return the lowest value allowed for the minimum length (first field of USER_PASSWORD_PATTERN) of the ...
encodedecode_dbpassconf($level=0)
Encode or decode database password in config file.
checkLoginPassEntity($usertotest, $passwordtotest, $entitytotest, $authmode, $context='')
Return a login if login/pass was successful.
dolTotpCheckCode($base32secret, $code, $timestamp=0, $period=30, $digits=6, $drift=1)
Check a code sent by a user against a secret, accepting a drift of some periods to tolerate a clock o...
dolTotpBase32Encode($bin)
Encode a binary string into base32 (alphabet of the RFC 4648, no padding).
isPasswordGenerationNoneForbidden()
Return if the 'none' password generation model (the one that applies no rule at all) is forbidden on ...
dolTotpStartSecondFactor($db, $login, $entity)
Start the second step of a two-factor authentication, just after a password has been validated.
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
dolTotpGetEnrollment($db, $fk_user)
Load the TOTP enrollment of a user.
if(!function_exists( 'dol_loginfunction')) makesalt($type=CRYPT_SALT_LENGTH)
Initialise the salt for the crypt function.
dolTotpGetCode($base32secret, $timestep, $digits=6, $algo='sha1')
Compute the TOTP code (RFC 6238) of a secret for one time step.
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.
dolEncrypt($chain, $key='', $ciphering='', $forceseed='', $obfuscationmode='dolcrypt')
Encode a string with a symmetric encryption.