39 if ($mode ==
'user') {
40 $t = getenv(
'APACHE_RUN_USER');
42 if ($mode ==
'group') {
43 $t = getenv(
'APACHE_RUN_GROUP');
63 if ($entitytotest ==
'') {
67 dol_syslog(
"checkLoginPassEntity usertotest=".$usertotest.
" entitytotest=".$entitytotest.
" authmode=".implode(
',', $authmode));
73 foreach ($authmode as $mode) {
74 if ($test && $mode && !$login) {
77 $authfile =
'functions_'.$mode.
'.php';
80 $dirlogin = array_merge(array(
"/core/login"), (array) $conf->modules_parts[
'login']);
81 foreach ($dirlogin as $reldir) {
86 $tmpnewauthfile = $newdir.(preg_match(
'/\/$/', $newdir) ?
'' :
'/').$authfile;
87 if (is_file($tmpnewauthfile)) {
88 $fullauthfile = $tmpnewauthfile;
94 $result = include_once $fullauthfile;
96 if ($fullauthfile && $result) {
98 $function =
'check_user_password_'.$mode;
99 $login = call_user_func($function, $usertotest, $passwordtotest, $entitytotest, $context);
100 if ($login && $login !=
'--bad-login-validity--') {
103 $conf->authmode = $mode;
110 dol_syslog(
"Authentication KO - failed to load file '".$authfile.
"'", LOG_ERR);
113 $langs->loadLangs(array(
'other',
'main',
'errors'));
115 $_SESSION[
"dol_loginmesg"] = (empty($_SESSION[
"dol_loginmesg"]) ?
'' : $_SESSION[
"dol_loginmesg"].
', ').$langs->transnoentitiesnoconv(
"ErrorFailedToLoadLoginFileForMode", $mode);
125if (!function_exists(
'dol_loginfunction')) {
135 function dol_loginfunction($langs, $conf, $mysoc)
137 global $dolibarr_main_demo, $dolibarr_main_force_https;
138 global $db, $hookmanager;
140 $langs->loadLangs(array(
"main",
"other",
"help",
"admin"));
143 $hookmanager->initHooks(array(
'mainloginpage'));
145 $main_authentication = $conf->file->main_authentication;
147 $session_name = session_name();
152 $appli = constant(
'DOL_APPLICATION_TITLE');
153 $title = $appli.(getDolGlobalString(
'MAIN_OPTIMIZEFORTEXTBROWSER') ?
'' :
' '.constant(
'DOL_VERSION'));
157 $titletruedolibarrversion = constant(
'DOL_VERSION');
178 if (!empty($conf->modules_parts[
'tpl'])) {
179 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array(
'/core/tpl/'));
180 foreach ($dirtpls as $reldir) {
182 if (file_exists($tmp)) {
183 $template_dir = preg_replace(
'/login\.tpl\.php$/',
'', $tmp);
188 $template_dir = DOL_DOCUMENT_ROOT.
"/core/tpl/";
193 $prefix = dol_getprefix(
'');
194 $sessiontimeout =
'DOLSESSTIMEOUT_'.$prefix;
197 if (session_status() != PHP_SESSION_ACTIVE) {
198 if (PHP_VERSION_ID < 70300) {
199 session_set_cookie_params(0,
'/',
null, ((empty($dolibarr_main_force_https) &&
isHTTPS() ===
false) ?
false : true), true);
202 $sessioncookieparams = array(
206 'secure' => ((empty($dolibarr_main_force_https) &&
isHTTPS() ===
false) ?
false : true),
210 session_set_cookie_params($sessioncookieparams);
213 setcookie($sessiontimeout, $conf->global->MAIN_SESSION_TIMEOUT, 0,
"/",
'', (empty($dolibarr_main_force_https) ?
false : true), true);
217 if (
GETPOST(
'urlfrom',
'alpha')) {
218 $_SESSION[
"urlfrom"] =
GETPOST(
'urlfrom',
'alpha');
220 unset($_SESSION[
"urlfrom"]);
223 if (!
GETPOST(
"username",
'alpha')) {
224 $focus_element =
'username';
226 $focus_element =
'password';
231 if (!empty($dolibarr_main_demo)) {
232 $tab = explode(
',', $dolibarr_main_demo);
233 $demologin = $tab[0];
234 $demopassword = $tab[1];
238 $parameters = array(
'entity' =>
GETPOSTINT(
'entity'),
'switchentity' =>
GETPOSTINT(
'switchentity'));
239 $reshook = $hookmanager->executeHooks(
'getLoginPageOptions', $parameters);
240 $morelogincontent = $hookmanager->resPrint;
243 $parameters = array(
'entity' =>
GETPOSTINT(
'entity'),
'switchentity' =>
GETPOSTINT(
'switchentity'));
244 $reshook = $hookmanager->executeHooks(
'getLoginPageExtraOptions', $parameters);
245 $moreloginextracontent = $hookmanager->resPrint;
248 $parameters = array(
'entity' =>
GETPOSTINT(
'entity'),
'switchentity' =>
GETPOSTINT(
'switchentity'));
249 $reshook = $hookmanager->executeHooks(
'redirectAfterConnection', $parameters);
250 $php_self = $hookmanager->resPrint;
253 $login = (!empty($hookmanager->resArray[
'username']) ? $hookmanager->resArray[
'username'] : (
GETPOST(
"username",
"alpha") ?
GETPOST(
"username",
"alpha") : $demologin));
254 $password = $demopassword;
258 $urllogo = DOL_URL_ROOT.
'/theme/common/login_logo.png';
260 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small)) {
261 $urllogo = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.$mysoc->logo_small);
262 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.
'/logos/'.$mysoc->logo)) {
263 $urllogo = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/'.$mysoc->logo);
265 } elseif (!empty($mysoc->logo_squarred_small) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_squarred_small)) {
266 $urllogo = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.$mysoc->logo_squarred_small);
267 } elseif (is_readable(DOL_DOCUMENT_ROOT.
'/theme/dolibarr_logo.svg')) {
268 $urllogo = DOL_URL_ROOT.
'/theme/dolibarr_logo.svg';
273 $captcha_refresh =
'';
274 if (function_exists(
"imagecreatefrompng") &&
getDolGlobalString(
'MAIN_SECURITY_ENABLECAPTCHA')) {
276 $captcha_refresh =
img_picto($langs->trans(
"Refresh"),
'refresh',
'id="captcha_refresh_img"');
306 $dol_loginmesg = (!empty($_SESSION[
"dol_loginmesg"]) ? $_SESSION[
"dol_loginmesg"] :
'');
308 $favicon = DOL_URL_ROOT.
'/theme/dolibarr_256x256_color.png';
309 if (!empty($mysoc->logo_squarred_mini)) {
310 $favicon = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.$mysoc->logo_squarred_mini);
316 $jquerytheme =
'base';
322 $dol_hide_topmenu =
GETPOSTINT(
'dol_hide_topmenu');
323 $dol_hide_leftmenu =
GETPOSTINT(
'dol_hide_leftmenu');
324 $dol_optimize_smallscreen =
GETPOSTINT(
'dol_optimize_smallscreen');
325 $dol_no_mouse_hover =
GETPOSTINT(
'dol_no_mouse_hover');
326 $dol_use_jmobile =
GETPOSTINT(
'dol_use_jmobile');
329 include $template_dir.
'login.tpl.php';
334 $_SESSION[
"dol_loginmesg"] =
'';
369 $salt .= chr(mt_rand(64, 126));
372 $result = $saltprefix.$salt.$saltsuffix;
385 dol_syslog(
"encodedecode_dbpassconf level=".$level, LOG_DEBUG);
388 $passwd_crypted =
'';
390 if ($fp = fopen(DOL_DOCUMENT_ROOT.
'/conf/conf.php',
'r')) {
392 $buffer = fgets($fp, 4096);
397 if (preg_match(
'/^[^#]*dolibarr_main_db_encrypted_pass[\s]*=[\s]*(.*)/i', $buffer, $reg)) {
398 $val = trim($reg[1]);
399 $val = preg_replace(
'/^["\']/',
'', $val);
400 $val = preg_replace(
'/["\'][\s;]*$/',
'', $val);
402 $passwd_crypted = $val;
409 } elseif (preg_match(
'/^[^#]*dolibarr_main_db_pass[\s]*=[\s]*(.*)/i', $buffer, $reg)) {
410 $val = trim($reg[1]);
411 $val = preg_replace(
'/^["\']/',
'', $val);
412 $val = preg_replace(
'/["\'][\s;]*$/',
'', $val);
413 if (preg_match(
'/crypted:/i', $buffer)) {
416 $val = preg_replace(
'/crypted:/i',
'', $val);
417 $passwd_crypted = $val;
420 } elseif (preg_match(
'/^dolcrypt:([^:]+):(.*)$/i', $buffer, $reg)) {
423 $val = preg_replace(
'/crypted:([^:]+):/i',
'', $val);
424 $passwd_crypted = $val;
431 $passwd_crypted = $val;
442 $config .=
'$dolibarr_main_db_pass=\''.$passwd.
'\';
'."\n";
445 $config .= '$dolibarr_main_db_pass=\
''.$mode.$passwd_crypted.
'\';
'."\n";
448 //print 'passwd =
'.$passwd.' - passwd_crypted =
'.$passwd_crypted;
456 // Write new conf file
457 $file = DOL_DOCUMENT_ROOT.'/
conf/
conf.php
';
458 if ($fp = @fopen($file, 'w
')) {
459 fwrite($fp, $config);
464 // It's config file, so we
set read permission
for creator only.
470 dol_syslog(
"encodedecode_dbpassconf Failed to open conf.php file for writing", LOG_WARNING);
474 dol_syslog(
"encodedecode_dbpassconf Failed to read conf.php", LOG_ERR);
490 global $db, $conf, $langs, $user;
492 $generated_password =
'';
494 $lowercase =
"qwertyuiopasdfghjklzxcvbnm";
495 $uppercase =
"ASDFGHJKLZXCVBNMQWERTYUIOP";
496 $numbers =
"1234567890";
498 $nbofchar = round($length / 3);
499 $nbofcharlast = ($length - 2 * $nbofchar);
501 if (function_exists(
'random_int')) {
502 $max = strlen($lowercase) - 1;
503 for ($x = 0; $x < $nbofchar; $x++) {
504 $tmp = random_int(0, $max);
505 $randomCode .= $lowercase[$tmp];
507 $max = strlen($uppercase) - 1;
508 for ($x = 0; $x < $nbofchar; $x++) {
509 $tmp = random_int(0, $max);
510 $randomCode .= $uppercase[$tmp];
512 $max = strlen($numbers) - 1;
513 for ($x = 0; $x < $nbofcharlast; $x++) {
514 $tmp = random_int(0, $max);
515 $randomCode .= $numbers[$tmp];
518 $generated_password = str_shuffle($randomCode);
521 $max = strlen($lowercase) - 1;
522 for ($x = 0; $x < $nbofchar; $x++) {
523 $tmp = mt_rand(0, $max);
524 $randomCode .= $lowercase[$tmp];
526 $max = strlen($uppercase) - 1;
527 for ($x = 0; $x < $nbofchar; $x++) {
528 $tmp = mt_rand(0, $max);
529 $randomCode .= $uppercase[$tmp];
531 $max = strlen($numbers) - 1;
532 for ($x = 0; $x < $nbofcharlast; $x++) {
533 $tmp = mt_rand(0, $max);
534 $randomCode .= $numbers[$tmp];
537 $generated_password = str_shuffle($randomCode);
540 $nomclass =
"modGeneratePass".ucfirst($conf->global->USER_PASSWORD_GENERATED);
541 $nomfichier = $nomclass.
".class.php";
543 require_once DOL_DOCUMENT_ROOT.
"/core/modules/security/generate/".$nomfichier;
544 $genhandler =
new $nomclass($db, $conf, $langs, $user);
545 $generated_password = $genhandler->getNewGeneratedPassword();
550 if (is_array($replaceambiguouschars) && count($replaceambiguouschars) > 0) {
552 $max = strlen($numbers) - 1;
553 if (function_exists(
'random_int')) {
554 $tmp = random_int(0, $max);
555 $generated_password = str_replace($replaceambiguouschars, $numbers[$tmp], $generated_password);
557 $tmp = mt_rand(0, $max);
558 $generated_password = str_replace($replaceambiguouschars, $numbers[$tmp], $generated_password);
562 return $generated_password;
580 if (!empty($conf->use_javascript_ajax)) {
581 $out .=
"\n".
'<!-- Js code to suggest a security key -->';
582 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">';
583 $out .=
'jQuery(document).ready(function () {
584 jQuery("#'.dol_escape_js($htmlnameofbutton).
'").click(function() {
585 var currenttoken = jQuery("meta[name=anti-csrf-currenttoken]").attr("content");
586 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).
'");
587 jQuery.get( "'.DOL_URL_ROOT.
'/core/ajax/security.php", {
588 action: \'getrandompassword\',
589 generic: '.($generic ?
'1' :
'0').
',
593 if (jQuery("input#'.
dol_escape_js($htmlname).
'").attr("type") == "password") {
594 jQuery("input#'.
dol_escape_js($htmlname).
'").attr("type", "text");
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
isHTTPS()
Return if we are using a HTTPS connection Check HTTPS (no way to be modified by user but may be empty...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
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 formatted 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)
Output javascript 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 successful.
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
if(!function_exists( 'dol_loginfunction')) makesalt($type=CRYPT_SALT_LENGTH)
Initialise the salt for the crypt function.
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 symmetric encryption.