Merge branch 'MDL-76478-password-unmask' of https://github.com/brendanheywood/moodle

This commit is contained in:
Andrew Nicols 2023-02-15 23:07:23 +08:00
commit 3db03d69b5
3 changed files with 10 additions and 15 deletions

View File

@ -54,14 +54,19 @@ class MoodleQuickForm_password extends HTML_QuickForm_password implements templa
*/
public function __construct($elementName=null, $elementLabel=null, $attributes=null) {
global $CFG;
// no standard mform in moodle should allow autocomplete of passwords
// No standard mform in moodle should allow autocomplete of passwords.
if (empty($attributes)) {
$attributes = array('autocomplete'=>'off');
$attributes = ['autocomplete' => 'new-password'];
} else if (is_array($attributes) && empty($attributes['autocomplete'])) {
$attributes['autocomplete'] = 'off';
$attributes['autocomplete'] = 'new-password';
} else if (is_array($attributes) && $attributes['autocomplete'] === 'off') {
// A value of 'off' is ignored in all modern browsers and password
// managers and should be new-password instead.
$attributes['autocomplete'] = 'new-password';
} else if (is_string($attributes)) {
if (strpos($attributes, 'autocomplete') === false) {
$attributes .= ' autocomplete="off" ';
$attributes .= ' autocomplete="new-password" ';
}
}

View File

@ -52,16 +52,6 @@ class MoodleQuickForm_passwordunmask extends MoodleQuickForm_password {
* or an associative array
*/
public function __construct($elementName=null, $elementLabel=null, $attributes=null) {
// no standard mform in moodle should allow autocomplete of passwords
if (empty($attributes)) {
$attributes = array('autocomplete'=>'off');
} else if (is_array($attributes)) {
$attributes['autocomplete'] = 'off';
} else {
if (strpos($attributes, 'autocomplete') === false) {
$attributes .= ' autocomplete="off" ';
}
}
$this->_persistantFreeze = true;
parent::__construct($elementName, $elementLabel, $attributes);

View File

@ -59,7 +59,7 @@
{{# error }}
autofocus aria-describedby="{{ element.iderror }}"
{{/ error }}
{{{ attributes }}}
{{{ element.attributes }}}
>
</span>
{{^ element.frozen }}