0

I have a password field which currently displays the current password. How can I force the input to be displayed as blank? From the documentation here, it seems that #default_value or #value don't work (so I can give them an empty string as a value). How can I do this?

  • That'll be your browser saving the password, Drupal doesn't get involved. Clear the saved passwords in your browser and it should disappear – Clive Nov 6 '12 at 18:50
  • Cleared cached, saved passwords and form data in Chrome, but the password is still shown in its input. – linkyndy Nov 6 '12 at 18:53
  • Easy test...open up the same page in another browser. Is the password still there? – Clive Nov 6 '12 at 19:31
  • @Clive, most modern browsers will honor the autocomplete attribute on forms and input elements. – mpdonadio Nov 6 '12 at 19:32
  • @MPD Yeah I just saw your answer, I've already copied it into one of my utility modules...gracias :) – Clive Nov 6 '12 at 19:32
2

We have a client who runs a security scan that flags login forms that have autocomplete enabled, and have been using this solution for a few years now:

/**
 * Implements hook_form_alter().
 *
 * Remove autocomplete from all user forms.
 * Based on http://www.midwesternmac.com/blogs/jeff-geerling/disabling-autocomplete-forms
 */
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if (strpos($form_id, 'user_') === 0) {
    $form['#attributes']['autocomplete'] = 'off';
  }
}
  • It doesn't work with unsetting autocomplete on either the input or the entire form. The password field is still not empty. – linkyndy Nov 6 '12 at 19:39
  • 1
    Not sure what is going on. This approach has worked for me for a while. You may have a browser plugin or the OS may be interfering here. – mpdonadio Nov 7 '12 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.