19declare(strict_types=1);
25use Psr\Http\Message\ServerRequestInterface;
37 private readonly ServerRequestInterface
$request;
51 $this->
user = $DIC->user();
52 $this->
ctrl = $DIC->ctrl();
53 $this->
error = $DIC[
'ilErr'];
54 $this->
lng = $DIC->language();
56 $this->tpl =
$DIC->ui()->mainTemplate();
57 $this->request =
$DIC->http()->request();
58 $this->ui_factory =
$DIC->ui()->factory();
59 $this->ui_renderer =
$DIC->ui()->renderer();
60 $this->password_manager = LocalUserPasswordManager::getInstance();
61 $this->
lng->loadLanguageModule(
'user');
66 $this->tpl->setTitle($this->
lng->txt(
'chg_password'));
67 $cmd = $this->
ctrl->getCmd();
70 if (method_exists($this, $cmd)) {
73 $this->
error->raiseError($this->
lng->txt(
'permission_denied'), $this->error->MESSAGE);
82 bool $hide_form =
false,
87 if ($this->
user->isPasswordChangeDemanded()) {
88 $this->tpl->setOnScreenMessage(
89 $this->tpl::MESSAGE_TYPE_INFO,
90 $this->
lng->txt(
'password_change_on_first_login_demand')
92 } elseif ($this->
user->isPasswordExpired()) {
93 $msg = $this->
lng->txt(
'password_expired');
94 $password_age = $this->
user->getPasswordAge();
95 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_INFO, sprintf($msg, $password_age));
98 if (!$form && !$hide_form) {
101 $this->tpl->setContent(
102 !$hide_form ? $this->ui_renderer->render($form) : $this->ui_renderer->render($message_box)
104 $this->tpl->printToStdout();
108 ?ServerRequestInterface $request =
null,
112 if ($this->password_manager->allowPasswordChange($this->user)) {
113 $pw_info_set =
false;
115 $cpass = $this->ui_factory->input()->field()->password(
116 $this->
lng->txt(self::CURRENT_PASSWORD),
121 if ($this->
user->getPasswd()) {
122 $cpass = $cpass->withRequired(
true);
124 $cpass = $cpass->withRevelation(
true);
125 $cpass_error = $errors[self::CURRENT_PASSWORD] ?? [];
126 if ($cpass_error !== []) {
127 $cpass = $cpass->withError(implode(
'<br>', $cpass_error));
129 $cpass = $cpass->withAdditionalTransformation(
133 LocalUserPasswordManager::getInstance()->verifyPassword(
137 }, $this->
lng->txt(
'passwd_wrong'))
140 $items[self::CURRENT_PASSWORD] = $cpass;
144 $ipass = $this->ui_factory->input()->field()->password(
145 $this->
lng->txt(
'desired_password'),
147 if ($pw_info_set ===
false) {
150 $ipass = $ipass->withRequired(
true);
151 $ipass = $ipass->withRevelation(
true);
152 $ipass_error = $errors[self::NEW_PASSWORD] ?? [];
153 if ($ipass_error !== []) {
154 $ipass = $ipass->withError(implode(
'<br>', $ipass_error));
156 $ipass = $ipass->withAdditionalTransformation(
162 if ($custom_error !==
'' && $custom_error !==
null) {
163 return $custom_error;
166 return $this->
lng->txt(
'passwd_invalid');
169 $ipass = $ipass->withAdditionalTransformation(
170 $this->
refinery->custom()->constraint(
178 function (Closure $cls,
Password $value):
string {
185 return $this->
lng->txt($error_lng_var ??
'');
189 $items[self::NEW_PASSWORD] = $ipass;
191 switch ($this->
user->getAuthMode(
true)) {
193 $title = $this->
lng->txt(
'chg_password');
198 $title = $this->
lng->txt(
'chg_ilias_password');
202 $section = $this->ui_factory->input()->field()->section($items, $title);
203 $items = [
'password' => $section];
206 return $this->ui_factory->input()->container()->form()->standard(
207 $this->
ctrl->getLinkTarget($this,
'savePassword'),
209 )->withSubmitLabel($this->
lng->txt(
'save'));
212 public function savePassword(): void
214 if (!$this->password_manager->allowPasswordChange($this->user)) {
215 $this->
ctrl->redirect($this,
'showPersonalData');
220 $form = $this->getPasswordForm()->withRequest($this->request);
221 $section = $form->getInputs()[
'password'];
226 $cp = $section->getInputs()[self::CURRENT_PASSWORD] ??
null;
227 $np = $section->getInputs()[self::NEW_PASSWORD];
228 $errors = [self::CURRENT_PASSWORD => [], self::NEW_PASSWORD => []];
230 if (!$form->getError()) {
232 if ($cp && $cp->getError()) {
234 $errors[self::CURRENT_PASSWORD][] = $cp->getError();
236 if ($np->getError()) {
238 $errors[self::NEW_PASSWORD][] = $np->getError();
241 $entered_current_password = $cp ? $cp->getValue() :
'';
242 $entered_new_password = $np->getValue();
245 $entered_current_password === $entered_new_password &&
246 ($this->
user->isPasswordExpired() || $this->user->isPasswordChangeDemanded())
249 $errors[self::NEW_PASSWORD][] = $this->
lng->txt(
'new_pass_equals_old_pass');
253 $this->
user->resetPassword($entered_new_password);
254 if ($entered_current_password !== $entered_new_password) {
255 $this->
user->setLastPasswordChangeToNow();
256 $this->
user->setPasswordPolicyResetStatus(
false);
257 $this->
user->update();
261 $this->tpl->setOnScreenMessage(
262 $this->tpl::MESSAGE_TYPE_SUCCESS,
263 $this->
lng->txt(
'saved_successfully'),
268 $this->
ctrl->redirectToURL($target);
273 $this->ui_factory->messageBox()->success($this->lng->txt(
'saved_successfully'))
281 $this->showPassword($this->getPasswordForm($this->request, $errors));
Builds a Color from either hex- or rgb values.
A password is used as part of credentials for authentication.
const int AUTH_SHIBBOLETH
Error Handling & global info handling.
readonly UIRenderer $ui_renderer
readonly LocalUserPasswordManager $password_manager
readonly ilErrorHandling $error
readonly ilCtrlInterface $ctrl
readonly UIFactory $ui_factory
showPassword(?Form $form=null, bool $hide_form=false, ?MessageBox $message_box=null)
readonly Refinery $refinery
readonly ilGlobalTemplateInterface $tpl
const string CURRENT_PASSWORD
getPasswordForm(?ServerRequestInterface $request=null, array $errors=[])
readonly ServerRequestInterface $request
const string NEW_PASSWORD
const string CMD_SHOW_PASSWORD
const string CMD_SAVE_PASSWORD
static isPassword(string $a_passwd, ?string &$customError=null)
static isPasswordValidForUserContext(string $clear_text_password, $user, ?string &$error_language_variable=null)
static getPasswordRequirementsInfo()
infotext for ilPasswordInputGUI setInfo()
static get(string $a_var)
static set(string $a_var, $a_val)
Set a value.
An entity that renders components to a string output.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))