hasPasswordSet()) { logNewMessage(LOG_ERR, 'Invalid attempt to set initial config password'); die(); } setlanguage(); if (!empty($_POST)) { validateSecurityToken(); } $message = null; // check if user already pressed button if (isset($_POST['changePassword'])) { // check new password $password1 = $_POST['password1']; $password2 = $_POST['password2']; if ($password1 == '') { $message = new htmlStatusMessage('ERROR', _('No password was entered!')); printContent($message); exit(); } // check if passwords match if ($password1 != $password2) { $message = new htmlStatusMessage('ERROR', _('Passwords are different!')); printContent($message); exit(); } // check password strength $pwdPolicyResult = isValidConfigurationPassword($password1); if (!$pwdPolicyResult) { $message = new htmlStatusMessage('ERROR', _('Please enter at least 8 characters including letters, a number and a symbol.')); printContent($message); exit(); } // set new password $cfgMain->setPassword($password1); try { $cfgMain->save(); metaRefresh('config/mainlogin.php'); exit(); } catch (LAMException $e) { $message = new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage()); } } printContent($message); /** * Displays the content area * * @param htmlStatusMessage|null $message status message * @param bool $showPasswordInputs show password input fields */ function printContent(?htmlStatusMessage $message = null, bool $showPasswordInputs = true): void { echo ' '; printHeaderContents('LDAP Account Manager', '..'); echo ' '; printJsIncludes('..'); echo '
'; echo "
\n"; addSecurityTokenToSession(); $container = new htmlResponsiveRow(); if ($message !== null) { $container->addVerticalSpacer('1rem'); $container->add($message); } $container->addVerticalSpacer('2rem'); if ($showPasswordInputs) { $container->add(new htmlTitle(_('Initial configuration'))); $container->addVerticalSpacer('3rem'); $container->add(new htmlOutputText(_("Please enter your new LAM main configuration password.")), 12, 12, 12, 'text-center'); $container->addVerticalSpacer('2rem'); $pwdInput1 = new htmlResponsiveInputField(_('New password'), 'password1', ''); $pwdInput1->setIsPassword(true, true, true); $container->add($pwdInput1); $pwdInput2 = new htmlResponsiveInputField(_('Repeat password'), 'password2', ''); $pwdInput2->setIsPassword(true); $pwdInput2->setSameValueFieldID('password1'); $container->add($pwdInput2); $container->addVerticalSpacer('1rem'); $container->add(new htmlButton('changePassword', _("Submit")), 12, 12, 12, 'text-center'); addSecurityTokenToMetaHTML($container); $container->add(new htmlJavaScript('checkFieldsHaveSameValues("password1", "password2");')); } parseHtml(null, $container, [], false, 'user'); echo '



'; }