From d1482bee15a6d3ff35993a31e6475bddfb44487a Mon Sep 17 00:00:00 2001 From: Mateusz Uzdowski Date: Wed, 12 Jun 2013 09:09:51 +1200 Subject: [PATCH] Add autocomplete=off switch for the password field. Some clients require disabling of the browser password handling mechanisms. Add a switch to make it possible without hacking the core. No change to default behaviour. --- forms/PasswordField.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/forms/PasswordField.php b/forms/PasswordField.php index 156deb8be..21ac2e212 100644 --- a/forms/PasswordField.php +++ b/forms/PasswordField.php @@ -6,6 +6,14 @@ */ class PasswordField extends TextField { + /** + * Controls the autocomplete attribute on the field. + * + * Setting it to false will set the attribute to "off", which will hint the browser + * to not cache the password and to not use any password managers. + */ + private static $autocomplete; + /** * Returns an input field, class="text" and type="text" with an optional * maxlength @@ -21,10 +29,17 @@ class PasswordField extends TextField { public function getAttributes() { - return array_merge( + $attributes = array_merge( parent::getAttributes(), array('type' => 'password') ); + + $autocomplete = Config::inst()->get('PasswordField', 'autocomplete'); + if (isset($autocomplete)) { + $attributes['autocomplete'] = $autocomplete ? 'on' : 'off'; + } + + return $attributes; } /**