From 73e226c971c0594dc8f090abf620f16c6d51e3ed Mon Sep 17 00:00:00 2001 From: John Okely Date: Wed, 3 Feb 2016 05:32:40 +0000 Subject: [PATCH] MDL-52952 forms: Fix chrome autofilling passwords again In MDL-45772 a hack was introduced to some forms to stop browsers from putting the user's password into password fields in forms unrelated to logging in. Chrome now no longer fills the user's password in the first password field in the page. There now needs to be a plain text input above it for the username too. --- lib/formslib.php | 6 ++---- lib/weblib.php | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/formslib.php b/lib/formslib.php index 949b95706af..a113fc47370 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -189,10 +189,6 @@ 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 @@ -2644,6 +2640,8 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{ $this->_collapseButtons = ''; $formid = $form->getAttribute('id'); parent::startForm($form); + // HACK to prevent browsers from automatically inserting the user's password into the wrong fields. + $this->_hiddenHtml .= prevent_form_autofill_password(); if ($form->isFrozen()){ $this->_formTemplate = "\n
\n{content}\n
"; } else { diff --git a/lib/weblib.php b/lib/weblib.php index 9f5e7c7a9f5..c038edd06b6 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -3600,5 +3600,5 @@ function get_formatted_help_string($identifier, $component, $ajax = false, $a = * @return string HTML to prevent password autofill */ function prevent_form_autofill_password() { - return '
'; + return '
'; }