38 if ($mode ==
'user') {
39 $t = getenv(
'APACHE_RUN_USER');
41 if ($mode ==
'group') {
42 $t = getenv(
'APACHE_RUN_GROUP');
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');
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;
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") &&
getDolGlobalString(
'MAIN_SECURITY_ENABLECAPTCHA')) {
275 $captcha_refresh =
img_picto($langs->trans(
"Refresh"),
'refresh',
'id="captcha_refresh_img"');
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);
312 $favicon = $conf->global->MAIN_FAVICON_URL;
315 $jquerytheme =
'base';
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"] =
'';
368 $salt .= chr(mt_rand(64, 126));
371 $result = $saltprefix.$salt.$saltsuffix;
384 dol_syslog(
"encodedecode_dbpassconf level=".$level, LOG_DEBUG);
387 $passwd_crypted =
'';
389 if ($fp = fopen(DOL_DOCUMENT_ROOT.
'/conf/conf.php',
'r')) {
391 $buffer = fgets($fp, 4096);
396 if (preg_match(
'/^[^#]*dolibarr_main_db_encrypted_pass[\s]*=[\s]*(.*)/i', $buffer, $reg)) {
397 $val = trim($reg[1]);
398 $val = preg_replace(
'/^["\']/',
'', $val);
399 $val = preg_replace(
'/["\'][\s;]*$/',
'', $val);
401 $passwd_crypted = $val;
408 } elseif (preg_match(
'/^[^#]*dolibarr_main_db_pass[\s]*=[\s]*(.*)/i', $buffer, $reg)) {
409 $val = trim($reg[1]);
410 $val = preg_replace(
'/^["\']/',
'', $val);
411 $val = preg_replace(
'/["\'][\s;]*$/',
'', $val);
412 if (preg_match(
'/crypted:/i', $buffer)) {
415 $val = preg_replace(
'/crypted:/i',
'', $val);
416 $passwd_crypted = $val;
419 } elseif (preg_match(
'/^dolcrypt:([^:]+):(.*)$/i', $buffer, $reg)) {
422 $val = preg_replace(
'/crypted:([^:]+):/i',
'', $val);
423 $passwd_crypted = $val;
430 $passwd_crypted = $val;
441 $config .=
'$dolibarr_main_db_pass=\''.$passwd.
'\';
'."\n";
444 $config .= '$dolibarr_main_db_pass=\
''.$mode.$passwd_crypted.
'\';
'."\n";
447 //print 'passwd =
'.$passwd.' - passwd_crypted =
'.$passwd_crypted;
455 // Write new conf file
456 $file = DOL_DOCUMENT_ROOT.'/
conf/
conf.php
';
457 if ($fp = @fopen($file, 'w
')) {
463 // It's config file, so we
set read permission
for creator only.
469 dol_syslog(
"encodedecode_dbpassconf Failed to open conf.php file for writing", LOG_WARNING);
473 dol_syslog(
"encodedecode_dbpassconf Failed to read conf.php", LOG_ERR);
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);
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;
579 if (!empty($conf->use_javascript_ajax)) {
580 $out .=
"\n".
'<!-- Js code to suggest a security key -->';
581 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">';
582 $out .=
'jQuery(document).ready(function () {
583 jQuery("#'.dol_escape_js($htmlnameofbutton).
'").click(function() {
584 var currenttoken = jQuery("meta[name=anti-csrf-currenttoken]").attr("content");
585 console.log("We click on the button '.
dol_escape_js($htmlnameofbutton).
' to suggest a key. anti-csrf-currentotken is "+currenttoken+". We will fill '.
dol_escape_js($htmlname).
'");
586 jQuery.get( "'.DOL_URL_ROOT.
'/core/ajax/security.php", {
587 action: \'getrandompassword\',
588 generic: '.($generic ?
'1' :
'0').
',
592 if (jQuery("input#'.
dol_escape_js($htmlname).
'").attr("type") == "password") {
593 jQuery("input#'.
dol_escape_js($htmlname).
'").attr("type", "text");
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
isHTTPS()
Return if we are using a HTTPS connexion Check HTTPS (no way to be modified by user but may be empty ...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_htmloutput_events($disabledoutputofmessages=0)
Print formated messages to output (Used to show messages on html output).
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...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null, $include=null)
Return array of possible common substitutions.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
conf($dolibarr_main_document_root)
Load conf file (file must exists)
if(empty($reshook)) $dol_url_root
View.
dolJSToSetRandomPassword($htmlname, $htmlnameofbutton='generate_token', $generic=1)
Ouput javacript to autoset a generated password using default module into a HTML element.
dol_getwebuser($mode)
Return user/group account of web server.
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 successfull.
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
if(!function_exists( 'dol_loginfunction')) makesalt($type=CRYPT_SALT_LENGTH)
Fonction pour initialiser un salt pour la fonction crypt.
dol_encode($chain, $key='1')
Encode a string with base 64 algorithm + specific delta change.
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
dolDecrypt($chain, $key='')
Decode a string with a symetric encryption.