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')) {
136 function dol_loginfunction($langs,
$conf, $mysoc)
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;
205 if (session_status() != PHP_SESSION_ACTIVE) {
206 if (PHP_VERSION_ID < 70300) {
207 session_set_cookie_params(0,
'/',
null, !(empty($dolibarr_main_force_https) &&
isHTTPS() ===
false),
true);
210 $sessioncookieparams = array(
214 'secure' => !(empty($dolibarr_main_force_https) &&
isHTTPS() ===
false),
218 session_set_cookie_params($sessioncookieparams);
221 setcookie($sessiontimeout,
getDolGlobalString(
'MAIN_SESSION_TIMEOUT'), 0,
"/",
'', !empty($dolibarr_main_force_https),
true);
225 if (
GETPOST(
'urlfrom',
'alpha')) {
226 $_SESSION[
"urlfrom"] =
GETPOST(
'urlfrom',
'alpha');
228 unset($_SESSION[
"urlfrom"]);
231 if (!
GETPOST(
"username",
'alpha')) {
232 $focus_element =
'username';
234 $focus_element =
'password';
239 if (!empty($dolibarr_main_demo)) {
240 $tab = explode(
',', $dolibarr_main_demo);
241 $demologin = $tab[0];
242 $demopassword = $tab[1];
246 $parameters = array(
'entity' =>
GETPOSTINT(
'entity'),
'switchentity' =>
GETPOSTINT(
'switchentity'));
247 $reshook = $hookmanager->executeHooks(
'getLoginPageOptions', $parameters);
248 $morelogincontent = $hookmanager->resPrint;
251 $parameters = array(
'entity' =>
GETPOSTINT(
'entity'),
'switchentity' =>
GETPOSTINT(
'switchentity'));
252 $reshook = $hookmanager->executeHooks(
'getLoginPageExtraOptions', $parameters);
253 $moreloginextracontent = $hookmanager->resPrint;
256 $parameters = array(
'entity' =>
GETPOSTINT(
'entity'),
'switchentity' =>
GETPOSTINT(
'switchentity'));
257 $reshook = $hookmanager->executeHooks(
'redirectAfterConnection', $parameters);
258 $php_self = $hookmanager->resPrint;
261 $login = (!empty($hookmanager->resArray[
'username']) ? $hookmanager->resArray[
'username'] : (
GETPOST(
"username",
"alpha") ?
GETPOST(
"username",
"alpha") : $demologin));
262 $password = $demopassword;
266 $urllogo = DOL_URL_ROOT.
'/theme/common/login_logo.png';
268 if (!empty($mysoc->logo_small) && is_readable(
$conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_small)) {
269 $urllogo = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.$mysoc->logo_small);
270 } elseif (!empty($mysoc->logo) && is_readable(
$conf->mycompany->dir_output.
'/logos/'.$mysoc->logo)) {
271 $urllogo = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/'.$mysoc->logo);
273 } elseif (!empty($mysoc->logo_squarred_small) && is_readable(
$conf->mycompany->dir_output.
'/logos/thumbs/'.$mysoc->logo_squarred_small)) {
274 $urllogo = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.$mysoc->logo_squarred_small);
275 } elseif (is_readable(DOL_DOCUMENT_ROOT.
'/theme/dolibarr_logo.svg')) {
276 $urllogo = DOL_URL_ROOT.
'/theme/dolibarr_logo.svg';
312 $dol_loginmesg = (!empty($_SESSION[
"dol_loginmesg"]) ? $_SESSION[
"dol_loginmesg"] :
'');
314 $favicon = DOL_URL_ROOT.
'/theme/dolibarr_256x256_color.png';
315 if (!empty($mysoc->logo_squarred_mini)) {
316 $favicon = DOL_URL_ROOT.
'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode(
'logos/thumbs/'.$mysoc->logo_squarred_mini);
322 $jquerytheme =
'base';
328 $dol_hide_topmenu =
GETPOSTINT(
'dol_hide_topmenu');
329 $dol_hide_leftmenu =
GETPOSTINT(
'dol_hide_leftmenu');
330 $dol_optimize_smallscreen =
GETPOSTINT(
'dol_optimize_smallscreen');
331 $dol_no_mouse_hover =
GETPOSTINT(
'dol_no_mouse_hover');
332 $dol_use_jmobile =
GETPOSTINT(
'dol_use_jmobile');
335 include $template_dir.
'login.tpl.php';
340 $_SESSION[
"dol_loginmesg"] =
'';
375 $salt .= chr(mt_rand(64, 126));
378 $result = $saltprefix.$salt.$saltsuffix;
391 dol_syslog(
"encodedecode_dbpassconf level=".$level, LOG_DEBUG);
394 $passwd_crypted =
'';
396 if ($fp = fopen(DOL_DOCUMENT_ROOT.
'/conf/conf.php',
'r')) {
398 $buffer = fgets($fp, 4096);
404 if (preg_match(
'/^[^#]*dolibarr_main_db_encrypted_pass[\s]*=[\s]*(.*)/i', $buffer, $reg)) {
405 $val = trim($reg[1]);
406 $val = preg_replace(
'/^["\']/',
'', $val);
407 $val = preg_replace(
'/["\'][\s;]*$/',
'', $val);
409 $passwd_crypted = $val;
416 } elseif (preg_match(
'/^[^#]*dolibarr_main_db_pass[\s]*=[\s]*(.*)/i', $buffer, $reg)) {
417 $val = trim($reg[1]);
418 $val = preg_replace(
'/^["\']/',
'', $val);
419 $val = preg_replace(
'/["\'][\s;]*$/',
'', $val);
420 if (preg_match(
'/crypted:/i', $buffer)) {
423 $val = preg_replace(
'/crypted:/i',
'', $val);
424 $passwd_crypted = $val;
427 } elseif (preg_match(
'/^dolcrypt:([^:]+):(.*)$/i', $buffer, $reg)) {
430 $val = preg_replace(
'/crypted:([^:]+):/i',
'', $val);
431 $passwd_crypted = $val;
438 $passwd_crypted = $val;
449 $config .=
'$dolibarr_main_db_pass=\''.$passwd.
'\';
'."\n";
452 $config .= '$dolibarr_main_db_pass=\
''.$mode.$passwd_crypted.
'\';
'."\n";
455 //print 'passwd =
'.$passwd.' - passwd_crypted =
'.$passwd_crypted;
463 // Write new conf file
464 $file = DOL_DOCUMENT_ROOT.'/
conf/
conf.php
';
465 if ($fp = @fopen($file, 'w
')) {
466 fwrite($fp, $config);
471 // It's config file, so we
set read permission
for creator only.
477 dol_syslog(
"encodedecode_dbpassconf Failed to open conf.php file for writing", LOG_WARNING);
481 dol_syslog(
"encodedecode_dbpassconf Failed to read conf.php", LOG_ERR);
497 global $db,
$conf, $langs, $user;
499 $generated_password =
'';
501 $lowercase =
"qwertyuiopasdfghjklzxcvbnm";
502 $uppercase =
"ASDFGHJKLZXCVBNMQWERTYUIOP";
503 $numbers =
"1234567890";
505 $nbofchar = round($length / 3);
506 $nbofcharlast = ($length - 2 * $nbofchar);
508 if (function_exists(
'random_int')) {
509 $max = strlen($lowercase) - 1;
510 for ($x = 0; $x < $nbofchar; $x++) {
511 $tmp = random_int(0, $max);
512 $randomCode .= $lowercase[$tmp];
514 $max = strlen($uppercase) - 1;
515 for ($x = 0; $x < $nbofchar; $x++) {
516 $tmp = random_int(0, $max);
517 $randomCode .= $uppercase[$tmp];
519 $max = strlen($numbers) - 1;
520 for ($x = 0; $x < $nbofcharlast; $x++) {
521 $tmp = random_int(0, $max);
522 $randomCode .= $numbers[$tmp];
525 $generated_password = str_shuffle($randomCode);
528 $max = strlen($lowercase) - 1;
529 for ($x = 0; $x < $nbofchar; $x++) {
530 $tmp = mt_rand(0, $max);
531 $randomCode .= $lowercase[$tmp];
533 $max = strlen($uppercase) - 1;
534 for ($x = 0; $x < $nbofchar; $x++) {
535 $tmp = mt_rand(0, $max);
536 $randomCode .= $uppercase[$tmp];
538 $max = strlen($numbers) - 1;
539 for ($x = 0; $x < $nbofcharlast; $x++) {
540 $tmp = mt_rand(0, $max);
541 $randomCode .= $numbers[$tmp];
544 $generated_password = str_shuffle($randomCode);
547 $nomclass =
"modGeneratePass".ucfirst(
$conf->global->USER_PASSWORD_GENERATED);
548 $nomfichier = $nomclass.
".class.php";
550 require_once DOL_DOCUMENT_ROOT.
"/core/modules/security/generate/".$nomfichier;
551 $genhandler =
new $nomclass($db,
$conf, $langs, $user);
552 '@phan-var-force ModeleGenPassword $genhandler';
553 $generated_password = $genhandler->getNewGeneratedPassword();
558 if (is_array($replaceambiguouschars) && count($replaceambiguouschars) > 0) {
560 $max = strlen($numbers) - 1;
561 if (function_exists(
'random_int')) {
562 $tmp = random_int(0, $max);
563 $generated_password = str_replace($replaceambiguouschars, $numbers[$tmp], $generated_password);
565 $tmp = mt_rand(0, $max);
566 $generated_password = str_replace($replaceambiguouschars, $numbers[$tmp], $generated_password);
570 return $generated_password;
588 if (!empty(
$conf->use_javascript_ajax)) {
589 $out .=
"\n".
'<!-- Js code to suggest a security key -->';
590 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">';
591 $out .=
'jQuery(document).ready(function () {
592 jQuery("#'.dol_escape_js($htmlnameofbutton).
'").click(function() {
593 var currenttoken = jQuery("meta[name=anti-csrf-currenttoken]").attr("content");
594 console.log("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).
'");
595 jQuery.get( "'.DOL_URL_ROOT.
'/core/ajax/security.php", {
596 action: \'getrandompassword\',
597 generic: '.($generic ?
'1' :
'0').
',
601 if (jQuery("input#'.
dol_escape_js($htmlname).
'").attr("type") == "password") {
602 jQuery("input#'.
dol_escape_js($htmlname).
'").attr("type", "text");
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 a 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)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
$context
@method int call_trigger(string $triggerName, User $user)
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.