diff --git a/admin/search.php b/admin/search.php index dc39e04e127..82c5969992b 100644 --- a/admin/search.php +++ b/admin/search.php @@ -46,6 +46,8 @@ $resultshtml = admin_search_settings_html($query); // case insensitive search on echo '
'; echo '
'; echo ''; +// HACK to prevent browsers from automatically inserting the user's password into the wrong fields. +echo prevent_form_autofill_password(); echo '
'; echo '
'; echo '
'; diff --git a/admin/settings.php b/admin/settings.php index 2acbc835e0e..e8f57825e76 100644 --- a/admin/settings.php +++ b/admin/settings.php @@ -77,6 +77,8 @@ if (empty($SITE->fullname)) { echo html_writer::input_hidden_params($PAGE->url); echo ''; echo ''; + // HACK to prevent browsers from automatically inserting the user's password into the wrong fields. + echo prevent_form_autofill_password(); echo $settingspage->output_html(); @@ -119,6 +121,8 @@ if (empty($SITE->fullname)) { echo html_writer::input_hidden_params($PAGE->url); echo ''; echo ''; + // HACK to prevent browsers from automatically inserting the user's password into the wrong fields. + echo prevent_form_autofill_password(); echo $OUTPUT->heading($settingspage->visiblename); echo $settingspage->output_html(); diff --git a/admin/upgradesettings.php b/admin/upgradesettings.php index 38a8f065ba1..f4aa61713c9 100644 --- a/admin/upgradesettings.php +++ b/admin/upgradesettings.php @@ -63,6 +63,8 @@ echo ''; echo '
'; echo ''; echo ''; +// HACK to prevent browsers from automatically inserting the user's password into the wrong fields. +echo prevent_form_autofill_password(); echo '
'; echo '
'; echo $newsettingshtml; diff --git a/lib/formslib.php b/lib/formslib.php index a12e20dee61..70bbbd11b32 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -188,6 +188,10 @@ abstract class moodleform { $this->_form->hardFreeze(); } + // HACK to prevent browsers from automatically inserting the user's password into the wrong fields. + $element = $this->_form->addElement('hidden'); + $element->setType('password'); + $this->definition(); $this->_form->addElement('hidden', 'sesskey', null); // automatic sesskey protection diff --git a/lib/weblib.php b/lib/weblib.php index bb671da80c0..60b65d3bb49 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -3561,3 +3561,13 @@ function get_formatted_help_string($identifier, $component, $ajax = false, $a = } return $data; } + +/** + * Renders a hidden password field so that browsers won't incorrectly autofill password fields with the user's password. + * + * @since 3.0 + * @return string HTML to prevent password autofill + */ +function prevent_form_autofill_password() { + return '
'; +}