19declare(strict_types=1);
25use Psr\Http\Message\ServerRequestInterface;
38 private readonly ServerRequestInterface
$request;
52 $this->
user = $DIC->user();
53 $this->
ctrl = $DIC->ctrl();
54 $this->
error = $DIC[
'ilErr'];
55 $this->
lng = $DIC->language();
57 $this->tpl =
$DIC->ui()->mainTemplate();
58 $this->request =
$DIC->http()->request();
59 $this->ui_factory =
$DIC->ui()->factory();
60 $this->ui_renderer =
$DIC->ui()->renderer();
61 $this->password_manager = LocalUserPasswordManager::getInstance();
62 $this->
lng->loadLanguageModule(
'user');
67 $this->tpl->setTitle($this->
lng->txt(
'chg_password'));
68 $cmd = $this->
ctrl->getCmd();
71 if (method_exists($this, $cmd .
'Cmd')) {
72 $this->{$cmd .
'Cmd'}();
74 $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->getPasswordAgeInDays();
95 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_INFO, sprintf($msg, $password_age));
98 if (!$form && !$hide_form) {
102 $this->tpl->setContent(
103 !$hide_form ? $this->ui_renderer->render($form) : $this->ui_renderer->render($message_box)
105 $this->tpl->printToStdout();
112 return $this->
refinery->custom()->constraint(
function (
Password $value) use (&$custom_error):
bool {
114 },
function (Closure $txt,
Password $value) use (&$custom_error):
string {
115 if ($custom_error !==
'' && $custom_error !==
null) {
116 return $custom_error;
119 return $this->
lng->txt(
'passwd_invalid');
125 $error_lng_var =
null;
127 return $this->
refinery->custom()->constraint(
128 function (
Password $value) use (&$error_lng_var):
bool {
135 function (Closure $cls,
Password $value) use (&$error_lng_var):
string {
136 return $this->
lng->txt($error_lng_var ??
'');
143 return $this->
refinery->custom()->transformation(
145 return trim($value->toString());
152 $entered_current_passwd =
null;
155 if ($this->password_manager->allowPasswordChange($this->user)) {
156 $pw_info_set =
false;
158 $current_passwd = $this->ui_factory
162 $this->
lng->txt(self::CURRENT_PASSWORD),
165 ->withRevelation(
true)
166 ->withAdditionalTransformation(
167 $this->
refinery->custom()->constraint(
168 function (
Password $value) use (&$entered_current_passwd):
bool {
169 $entered_current_passwd = $value;
173 LocalUserPasswordManager::getInstance()->verifyPassword(
178 $this->
lng->txt(
'passwd_wrong')
181 ->withAdditionalTransformation($this->passwordToString());
184 if ($this->
user->getPasswd()) {
185 $current_passwd = $current_passwd->withRequired(
true);
188 $items[self::CURRENT_PASSWORD] = $current_passwd;
191 $new_passwd = $this->ui_factory
195 $this->
lng->txt(
'desired_password'),
197 ->withRevelation(
true)
199 ->withAdditionalTransformation($this->securePasswordConstraint())
200 ->withAdditionalTransformation($this->validInUserContextConstraint())
201 ->withAdditionalTransformation(
202 $this->
refinery->custom()->constraint(
203 function (
Password $value) use (&$entered_current_passwd):
bool {
204 if ($entered_current_passwd ===
null) {
208 $passwords_equal = $entered_current_passwd->toString() === $value->
toString();
209 $is_forced_change = $this->user->isPasswordChangeDemanded()
210 || $this->user->isPasswordExpired();
212 return !($passwords_equal && $is_forced_change);
214 $this->
lng->txt(
'new_pass_equals_old_pass')
217 ->withAdditionalTransformation($this->passwordToString());
219 if ($pw_info_set ===
false) {
223 $items[self::NEW_PASSWORD] = $new_passwd;
225 switch ($this->
user->getAuthMode(
true)) {
227 $title = $this->
lng->txt(
'chg_password');
232 $title = $this->
lng->txt(
'chg_ilias_password');
238 $this->ui_factory->input()->field()->section($items, $title)
242 $form = $this->ui_factory
247 $this->
ctrl->getLinkTarget($this,
'savePassword'),
250 ->withSubmitLabel($this->
lng->txt(
'save'))
251 ->withAdditionalTransformation(
252 $this->
refinery->custom()->transformation(
static function (array $values): array {
253 return array_merge(...$values);
262 if (!$this->password_manager->allowPasswordChange($this->user)) {
263 $this->
ctrl->redirect($this,
'showPersonalData');
266 $form = $this->getPasswordForm()->withRequest($this->request);
267 if (!$form->getError()) {
268 $data = $form->getData();
269 $entered_current_passwd =
$data[self::CURRENT_PASSWORD] ??
'';
270 $entered_new_passwd =
$data[self::NEW_PASSWORD];
272 $this->
user->resetPassword($entered_new_passwd, $entered_new_passwd);
273 if ($entered_current_passwd !== $entered_new_passwd) {
274 $this->
user->setLastPasswordChangeToNow();
275 $this->
user->setPasswordPolicyResetStatus(
false);
276 $this->
user->update();
280 $this->tpl->setOnScreenMessage(
281 $this->tpl::MESSAGE_TYPE_SUCCESS,
282 $this->
lng->txt(
'saved_successfully'),
287 $this->
ctrl->redirectToURL($target);
289 $this->showPasswordCmd(
292 $this->ui_factory->messageBox()->success($this->lng->txt(
'saved_successfully'))
299 $this->showPasswordCmd($form);
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
securePasswordConstraint()
readonly UIFactory $ui_factory
readonly Refinery $refinery
validInUserContextConstraint()
readonly ilGlobalTemplateInterface $tpl
const string CURRENT_PASSWORD
readonly ServerRequestInterface $request
const string NEW_PASSWORD
const string CMD_SHOW_PASSWORD
showPasswordCmd(?Form $form=null, bool $hide_form=false, ?MessageBox $message_box=null)
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...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
if(!file_exists('../ilias.ini.php'))