I am trying to create a small module to turn off autocomplete for password for user login.

This is for PCI compliance and I think something that more people will look for.

I have never put a module together and have the following code, thanks to emunications.com.

I installed this but got the two errors at the bottom of this post. Can anyone help point me in the right direction?

Many thanks,

// $Id: autocomplete.module, v 1.2 2011/02/07

function autocomplete_form_user_login_alter(&$form, &$form_state, $form_id) {
$form['#attributes'][]['autocomplete'] = 'off';
}
function autocomplete_form_user_login_block_alter(&$form, &$form_state, $form_id) {
$form['#attributes'][]['autocomplete'] = 'off';
}

* warning: Missing argument 3 for autocomplete_form_user_login_block_alter() in /home/coghlanc/public_html/modules/autocomplete/autocomplete.module on line 6.
* warning: htmlspecialchars() expects parameter 1 to be string, array given in /home/coghlanc/public_html/includes/bootstrap.inc on line 857.

Comments

rbayliss’s picture

You only need the $form_id argument if you are using basic hook_form_alter(). You are altering a specific form, user_login, so you don't need and won't get the $form_id. So you should have:

// $Id: autocomplete.module, v 1.2 2011/02/07

function autocomplete_form_user_login_alter(&$form, &$form_state) {
$form['#attributes'][]['autocomplete'] = 'off';
}
function autocomplete_form_user_login_block_alter(&$form, &$form_state) {
$form['#attributes'][]['autocomplete'] = 'off';
}
paulcoghlan’s picture

Thanks, I have made the change and now only have a single error, below:

Haven't a clue why this would appear based upon the simple code in this module.

warning: htmlspecialchars() expects parameter 1 to be string, array given in /home/coghlanc/public_html/includes/bootstrap.inc on line 857.

rbayliss’s picture

$form['#attributes'][]['autocomplete'] = 'off';

should be

$form['attributes']['autocomplete'] = 'off';
paulcoghlan’s picture

Just posting in case future visitors has the same issue.

I re-inserted the [] in the code so what worked finally was this:

$form['attributes'][]['autocomplete'] = 'off';

Thanks for your help

Paul

greggles’s picture

It seems someone turned this into a module. I found this thread after posting this critique of the technique.

Note that all this module has done is hide the autocomplete. Someone could still use it if they can figure out that it would exist.

I wonder what module was adding this feature - it could have been possible to just disable that.

rbayliss’s picture

I don't believe the OP is talking about an autocomplete in the Drupal sense, just turning off the browser's tendency to remember your username (which is done with an HTML attribute on the input element)

greggles’s picture

Ah, I see. Thanks for explaining! I'll admit I didn't look as closely as I should have.

greggles’s picture

There's now a module to achieve this - http://drupal.org/project/pci_update

BrankoC’s picture

It is perhaps useful to know that browser manufacturers have started to disable this functionality for password managed login screens: https://bugzilla.mozilla.org/show_bug.cgi?id=956906

capfive’s picture

Correct, would be great if we knew the answer now, as we have a "ID" and "Pin" on our site which looks like a username and password field to the browser and it's trying to put site login details in there...

Jaypan’s picture

The answer was given earlier in this thread.

Set autocomplete to off.

capfive’s picture

I tried that but as said earlier in the post, some browsers are disabling this feature on password fields, which our PIN field is, so would be great if anyone know a way to set the password to autocomplete off, because the above code is not working

raghwendra’s picture

I got a module for no auto complete attribute that is here https://www.drupal.org/project/no_autocomplete. This is just work for password field and put attributes autocomplete="off".