62 if ($entitytotest ==
'') {
66 dol_syslog(
"checkLoginPassEntity usertotest=".$usertotest.
" entitytotest=".$entitytotest.
" authmode=".join(
',', $authmode));
72 foreach ($authmode as $mode) {
73 if ($test && $mode && !$login) {
76 $authfile =
'functions_'.$mode.
'.php';
79 $dirlogin = array_merge(array(
"/core/login"), (array) $conf->modules_parts[
'login']);
80 foreach ($dirlogin as $reldir) {
85 $tmpnewauthfile = $newdir.(preg_match(
'/\/$/', $newdir) ?
'' :
'/').$authfile;
86 if (is_file($tmpnewauthfile)) {
87 $fullauthfile = $tmpnewauthfile;
93 $result = include_once $fullauthfile;
95 if ($fullauthfile && $result) {
97 $function =
'check_user_password_'.$mode;
98 $login = call_user_func($function, $usertotest, $passwordtotest, $entitytotest, $context);
99 if ($login && $login !=
'--bad-login-validity--') {
102 $conf->authmode = $mode;
109 dol_syslog(
"Authentication KO - failed to load file '".$authfile.
"'", LOG_ERR);
112 $langs->loadLangs(array(
'other',
'main',
'errors'));
114 $_SESSION[
"dol_loginmesg"] = (empty($_SESSION[
"dol_loginmesg"]) ?
'' : $_SESSION[
"dol_loginmesg"].
', ').$langs->transnoentitiesnoconv(
"ErrorFailedToLoadLoginFileForMode", $mode);
124if (!function_exists(
'dol_loginfunction')) {
134 function dol_loginfunction($langs, $conf, $mysoc)
136 global $dolibarr_main_demo, $dolibarr_main_force_https;
137 global $db, $hookmanager;
139 $langs->loadLangs(array(
"main",
"other",
"help",
"admin"));
142 $hookmanager->initHooks(array(
'mainloginpage'));
144 $main_authentication = $conf->file->main_authentication;
146 $session_name = session_name();
151 $appli = constant(
'DOL_APPLICATION_TITLE');
152 $title = $appli.
' '.constant(
'DOL_VERSION');
153 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
154 $title = $conf->global->MAIN_APPLICATION_TITLE;
156 $titletruedolibarrversion = constant(
'DOL_VERSION');
177 if (!empty($conf->modules_parts[
'tpl'])) {
178 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array(
'/core/tpl/'));
179 foreach ($dirtpls as $reldir) {
181 if (file_exists($tmp)) {
182 $template_dir = preg_replace(
'/login\.tpl\.php$/',
'', $tmp);
187 $template_dir = DOL_DOCUMENT_ROOT.
"/core/tpl/";
192 $prefix = dol_getprefix(
'');
193 $sessiontimeout =
'DOLSESSTIMEOUT_'.$prefix;
195 if (!empty($conf->global->MAIN_SESSION_TIMEOUT)) {
196 if (session_status() != PHP_SESSION_ACTIVE) {
197 if (PHP_VERSION_ID < 70300) {
198 session_set_cookie_params(0,
'/',
null, ((empty($dolibarr_main_force_https) &&
isHTTPS() ===
false) ?
false : true), true);
201 $sessioncookieparams = array(
205 'secure' => ((empty($dolibarr_main_force_https) &&
isHTTPS() ===
false) ?
false : true),
209 session_set_cookie_params($sessioncookieparams);
212 setcookie($sessiontimeout, $conf->global->MAIN_SESSION_TIMEOUT, 0,
"/",
null, (empty($dolibarr_main_force_https) ?
false : true), true);
216 if (
GETPOST(
'urlfrom',
'alpha')) {
217 $_SESSION[
"urlfrom"] =
GETPOST(
'urlfrom',
'alpha');
219 unset($_SESSION[
"urlfrom"]);
222 if (!
GETPOST(
"username",
'alpha')) {
223 $focus_element =
'username';
225 $focus_element =
'password';
230 if (!empty($dolibarr_main_demo)) {
231 $tab = explode(
',', $dolibarr_main_demo);
232 $demologin = $tab[0];
233 $demopassword = $tab[1];
237 $parameters = array(
'entity' =>
GETPOST(
'entity',
'int'),
'switchentity' =>
GETPOST(
'switchentity',
'int'));
238 $reshook = $hookmanager->executeHooks(
'getLoginPageOptions', $parameters);
239 $morelogincontent = $hookmanager->resPrint;
242 $parameters = array(
'entity' =>
GETPOST(
'entity',
'int'),
'switchentity' =>
GETPOST(
'switchentity',
'int'));
243 $reshook = $hookmanager->executeHooks(
'getLoginPageExtraOptions', $parameters);
244 $moreloginextracontent = $hookmanager->resPrint;
247 $parameters = array(
'entity' =>
GETPOST(
'entity',
'int'),
'switchentity' =>
GETPOST(
'switchentity',
'int'));
248 $reshook = $hookmanager->executeHooks(
'redirectAfterConnection', $parameters);
249 $php_self = $hookmanager->resPrint;
252 $login = (!empty($hookmanager->resArray[
'username']) ? $hookmanager->resArray[
'username'] : (
GETPOST(
"username",
"alpha") ?
GETPOST(
"username",
"alpha") : $demologin));
253 $password = $demopassword;
257 $urllogo = DOL_URL_ROOT.
'/theme/common/login_logo.png';
259 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small)) {
260 $urllogo = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.$mysoc->logo_small);
261 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.
'/logos/'.$mysoc->logo)) {
262 $urllogo = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/'.$mysoc->logo);
264 } elseif (!empty($mysoc->logo_squarred_small) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_squarred_small)) {
265 $urllogo = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.$mysoc->logo_squarred_small);
266 } elseif (is_readable(DOL_DOCUMENT_ROOT.
'/theme/dolibarr_logo.svg')) {
267 $urllogo = DOL_URL_ROOT.
'/theme/dolibarr_logo.svg';
272 $captcha_refresh =
'';
273 if (function_exists(
"imagecreatefrompng") && !empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA)) {
275 $captcha_refresh =
img_picto($langs->trans(
"Refresh"),
'refresh',
'id="captcha_refresh_img"');
281 if (empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK) || empty($conf->global->MAIN_HELPCENTER_DISABLELINK)) {
282 if (empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK)) {
286 if (empty($conf->global->MAIN_HELPCENTER_DISABLELINK)) {
293 if (!empty($conf->global->MAIN_HOME)) {
296 $texttoshow =
make_substitutions($conf->global->MAIN_HOME, $substitutionarray, $langs);
302 $main_google_ad_client = ((!empty($conf->global->MAIN_GOOGLE_AD_CLIENT) && !empty($conf->global->MAIN_GOOGLE_AD_SLOT)) ? 1 : 0);
305 $dol_loginmesg = (!empty($_SESSION[
"dol_loginmesg"]) ? $_SESSION[
"dol_loginmesg"] :
'');
307 $favicon = DOL_URL_ROOT.
'/theme/dolibarr_256x256_color.png';
308 if (!empty($mysoc->logo_squarred_mini)) {
309 $favicon = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.$mysoc->logo_squarred_mini);
311 if (!empty($conf->global->MAIN_FAVICON_URL)) {
312 $favicon = $conf->global->MAIN_FAVICON_URL;
315 $jquerytheme =
'base';
316 if (!empty($conf->global->MAIN_USE_JQUERY_THEME)) {
317 $jquerytheme = $conf->global->MAIN_USE_JQUERY_THEME;
321 $dol_hide_topmenu =
GETPOST(
'dol_hide_topmenu',
'int');
322 $dol_hide_leftmenu =
GETPOST(
'dol_hide_leftmenu',
'int');
323 $dol_optimize_smallscreen =
GETPOST(
'dol_optimize_smallscreen',
'int');
324 $dol_no_mouse_hover =
GETPOST(
'dol_no_mouse_hover',
'int');
325 $dol_use_jmobile =
GETPOST(
'dol_use_jmobile',
'int');
328 include $template_dir.
'login.tpl.php';
333 $_SESSION[
"dol_loginmesg"] =
'';
489 global $db, $conf, $langs, $user;
491 $generated_password =
'';
493 $lowercase =
"qwertyuiopasdfghjklzxcvbnm";
494 $uppercase =
"ASDFGHJKLZXCVBNMQWERTYUIOP";
495 $numbers =
"1234567890";
497 $nbofchar = round($length / 3);
498 $nbofcharlast = ($length - 2 * $nbofchar);
500 if (function_exists(
'random_int')) {
501 $max = strlen($lowercase) - 1;
502 for ($x = 0; $x < $nbofchar; $x++) {
503 $tmp = random_int(0, $max);
504 $randomCode .= $lowercase[$tmp];
506 $max = strlen($uppercase) - 1;
507 for ($x = 0; $x < $nbofchar; $x++) {
508 $tmp = random_int(0, $max);
509 $randomCode .= $uppercase[$tmp];
511 $max = strlen($numbers) - 1;
512 for ($x = 0; $x < $nbofcharlast; $x++) {
513 $tmp = random_int(0, $max);
514 $randomCode .= $numbers[$tmp];
517 $generated_password = str_shuffle($randomCode);
520 $max = strlen($lowercase) - 1;
521 for ($x = 0; $x < $nbofchar; $x++) {
522 $tmp = mt_rand(0, $max);
523 $randomCode .= $lowercase[$tmp];
525 $max = strlen($uppercase) - 1;
526 for ($x = 0; $x < $nbofchar; $x++) {
527 $tmp = mt_rand(0, $max);
528 $randomCode .= $uppercase[$tmp];
530 $max = strlen($numbers) - 1;
531 for ($x = 0; $x < $nbofcharlast; $x++) {
532 $tmp = mt_rand(0, $max);
533 $randomCode .= $numbers[$tmp];
536 $generated_password = str_shuffle($randomCode);
538 } elseif (!empty($conf->global->USER_PASSWORD_GENERATED)) {
539 $nomclass =
"modGeneratePass".ucfirst($conf->global->USER_PASSWORD_GENERATED);
540 $nomfichier = $nomclass.
".class.php";
542 require_once DOL_DOCUMENT_ROOT.
"/core/modules/security/generate/".$nomfichier;
543 $genhandler =
new $nomclass($db, $conf, $langs, $user);
544 $generated_password = $genhandler->getNewGeneratedPassword();
549 if (is_array($replaceambiguouschars) && count($replaceambiguouschars) > 0) {
551 $max = strlen($numbers) - 1;
552 if (function_exists(
'random_int')) {
553 $tmp = random_int(0, $max);
554 $generated_password = str_replace($replaceambiguouschars, $numbers[$tmp], $generated_password);
556 $tmp = mt_rand(0, $max);
557 $generated_password = str_replace($replaceambiguouschars, $numbers[$tmp], $generated_password);
561 return $generated_password;