ILIAS  release_8 Revision v8.24
class.ilPasswordInputGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
27{
28 protected bool $skip_syntax_check = false;
29 protected string $value = "";
30 protected int $size = 20;
31 protected string $validateauthpost = "";
32 protected bool $requiredonauth = false;
33 protected int $maxlength = 0;
34 protected bool $use_strip_slashes = true;
38 protected bool $autocomplete_disabled = true;
39 protected string $retypevalue = "";
40 protected bool $retype = false;
41
42 public function __construct(
43 string $a_title = "",
44 string $a_postvar = ""
45 ) {
46 global $DIC;
47
48 $this->lng = $DIC->language();
49 parent::__construct($a_title, $a_postvar);
50 $this->setRetype(true);
51 $this->setSkipSyntaxCheck(false);
52 }
53
54 public function setValue(
55 string $a_value
56 ): void {
57 $this->value = $a_value;
58 }
59
60 public function getValue(): string
61 {
62 return $this->value;
63 }
64
65 public function setRetype(bool $a_val): void
66 {
67 $this->retype = $a_val;
68 }
69
70 public function getRetype(): bool
71 {
72 return $this->retype;
73 }
74
75 public function setRetypeValue(string $a_retypevalue): void
76 {
77 $this->retypevalue = $a_retypevalue;
78 }
79
80 public function getRetypeValue(): string
81 {
82 return $this->retypevalue;
83 }
84
85 public function setMaxLength(int $a_maxlength): void
86 {
87 $this->maxlength = $a_maxlength;
88 }
89
90 public function getMaxLength(): int
91 {
92 return $this->maxlength;
93 }
94
95 public function setSize(int $a_size): void
96 {
97 $this->size = $a_size;
98 }
99
100 public function setValueByArray(array $a_values): void
101 {
102 $this->setValue($a_values[$this->getPostVar()] ?? "");
103 $this->setRetypeValue($a_values[$this->getPostVar() . "_retype"] ?? "");
104 }
105
106 public function getSize(): int
107 {
108 return $this->size;
109 }
110
111 // Set Validate required status against authentication POST var.
112 public function setValidateAuthPost(string $a_validateauthpost): void
113 {
114 $this->validateauthpost = $a_validateauthpost;
115 }
116
117 public function getValidateAuthPost(): string
118 {
119 return $this->validateauthpost;
120 }
121
122 // Set input required, if authentication mode allows password setting.
123 public function setRequiredOnAuth(bool $a_requiredonauth): void
124 {
125 $this->requiredonauth = $a_requiredonauth;
126 }
127
128 public function getRequiredOnAuth(): bool
129 {
130 return $this->requiredonauth;
131 }
132
133 public function setSkipSyntaxCheck(bool $a_val): void
134 {
135 $this->skip_syntax_check = $a_val;
136 }
137
138 public function getSkipSyntaxCheck(): bool
139 {
140 return $this->skip_syntax_check;
141 }
142
143 public function setDisableHtmlAutoComplete(bool $a_value): void
144 {
145 $this->autocomplete_disabled = $a_value;
146 }
147
148 public function isHtmlAutoCompleteDisabled(): bool
149 {
150 return $this->autocomplete_disabled;
151 }
152
158 public function setUseStripSlashes(bool $a_stat): void
159 {
160 $this->use_strip_slashes = $a_stat;
161 }
162
163 public function getUseStripSlashes(): bool
164 {
165 return $this->use_strip_slashes;
166 }
167
168 public function checkInput(): bool
169 {
171
172 $pass_value = $this->getInput();
173 $retype_value = ($this->getUseStripSlashes())
174 ? $this->str($this->getPostVar() . "_retype")
175 : $this->raw($this->getPostVar() . "_retype");
176
177 if ($this->getRequired() && trim($pass_value) == "") {
178 $this->setAlert($lng->txt("msg_input_is_required"));
179 return false;
180 }
181 if ($this->getValidateAuthPost() != "") {
182 $auth = ilAuthUtils::_getAuthMode($this->str($this->getValidateAuthPost()));
183
184 // check, if password is required dependent on auth mode
185 if ($this->getRequiredOnAuth() && ilAuthUtils::_allowPasswordModificationByAuthMode($auth)
186 && trim($pass_value) == "") {
187 $this->setAlert($lng->txt("form_password_required_for_auth"));
188 return false;
189 }
190
191 // check, if password is allowed to be set for given auth mode
192 if (trim($pass_value) != "" &&
194 $this->setAlert($lng->txt("form_password_not_allowed_for_auth"));
195 return false;
196 }
197 }
198 if ($this->getRetype() &&
199 ($pass_value != $retype_value)) {
200 $this->setAlert($lng->txt("passwd_not_match"));
201 return false;
202 }
203 if (!$this->getSkipSyntaxCheck() &&
204 !ilSecuritySettingsChecker::isPassword($pass_value, $custom_error) &&
205 $pass_value != "") {
206 if ($custom_error != '') {
207 $this->setAlert($custom_error);
208 } else {
209 $this->setAlert($lng->txt("passwd_invalid"));
210 }
211 return false;
212 }
213
214 return $this->checkSubItemsInput();
215 }
216
217 public function getInput(): string
218 {
219 if ($this->getUseStripSlashes()) {
220 return $this->str($this->getPostVar());
221 }
222 return $this->raw($this->getPostVar());
223 }
224
225 public function render(): string
226 {
228
229 $ptpl = new ilTemplate("tpl.prop_password.html", true, true, "Services/Form");
230
231 if ($this->getRetype()) {
232 $ptpl->setCurrentBlock("retype");
233 $ptpl->setVariable("RSIZE", $this->getSize());
234 $ptpl->setVariable("RID", $this->getFieldId());
235 if ($this->getMaxLength() > 0) {
236 $ptpl->setCurrentBlock("rmaxlength");
237 $ptpl->setVariable("RMAXLENGTH", $this->getMaxLength());
238 $ptpl->parseCurrentBlock();
239 }
240 $ptpl->setVariable("RPOST_VAR", $this->getPostVar());
241
242 if ($this->isHtmlAutoCompleteDisabled()) {
243 $ptpl->setVariable("RAUTOCOMPLETE", "autocomplete=\"off\"");
244 }
245
246 // this is creating an "auto entry" in the setup, if the retype is missing
247 /*$retype_value = ($this->getRetypeValue() != "")
248 ? $this->getRetypeValue()
249 : $this->getValue();*/
250 $retype_value = $this->getRetypeValue();
251 $ptpl->setVariable("PROPERTY_RETYPE_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($retype_value));
252 if ($this->getDisabled()) {
253 $ptpl->setVariable(
254 "RDISABLED",
255 " disabled=\"disabled\""
256 );
257 }
258 $ptpl->setVariable("TXT_RETYPE", $lng->txt("form_retype_password"));
259 $ptpl->parseCurrentBlock();
260 }
261
262 if (strlen($this->getValue())) {
263 $ptpl->setCurrentBlock("prop_password_propval");
264 $ptpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($this->getValue()));
265 $ptpl->parseCurrentBlock();
266 }
267 $ptpl->setVariable("POST_VAR", $this->getPostVar());
268 $ptpl->setVariable("ID", $this->getFieldId());
269 $ptpl->setVariable("SIZE", $this->getSize());
270 if ($this->getMaxLength() > 0) {
271 $ptpl->setCurrentBlock("maxlength");
272 $ptpl->setVariable("MAXLENGTH", $this->getMaxLength());
273 $ptpl->parseCurrentBlock();
274 }
275 if ($this->getDisabled()) {
276 $ptpl->setVariable(
277 "DISABLED",
278 " disabled=\"disabled\""
279 );
280 }
281 if ($this->isHtmlAutoCompleteDisabled()) {
282 $ptpl->setVariable("AUTOCOMPLETE", "autocomplete=\"off\"");
283 }
284 if ($this->getRequired()) {
285 $ptpl->setVariable("REQUIRED", "required=\"required\"");
286 }
287 return $ptpl->get();
288 }
289
290 public function insert(ilTemplate $a_tpl): void
291 {
292 $html = $this->render();
293
294 $a_tpl->setCurrentBlock("prop_generic");
295 $a_tpl->setVariable("PROP_GENERIC", $html);
296 $a_tpl->parseCurrentBlock();
297 }
298}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
static _allowPasswordModificationByAuthMode($a_auth_mode)
Allow password modification.
static _getAuthMode(?string $a_auth_mode)
static prepareFormOutput($a_str, bool $a_strip=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkInput()
Check input, strip slashes etc.
setValueByArray(array $a_values)
__construct(string $a_title="", string $a_postvar="")
setMaxLength(int $a_maxlength)
setRequiredOnAuth(bool $a_requiredonauth)
setValidateAuthPost(string $a_validateauthpost)
setRetypeValue(string $a_retypevalue)
setDisableHtmlAutoComplete(bool $a_value)
setUseStripSlashes(bool $a_stat)
En/disable use of stripslashes.
static isPassword(string $a_passwd, ?string &$customError=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
global $DIC
Definition: feed.php:28
$auth
Definition: metadata.php:76
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
getValue()
Get the value that is displayed in the input client side.
Definition: Group.php:47
$lng