17

I'm developing a website. I'm using a single-page web-app style, so all of the different parts of the site are AJAX'd into index.php. When a user logs in and tells Firefox to remember his username and password, all input boxes on the site get auto-filled with that username and password. This is a problem on the form to change a password. How can i prevent Firefox from automatically filling out these fields? I already tried giving them different names and ids.

Edit: Someone has already asked this. Thanks Joel Coohorn.

Community
  • 1
  • 1
Christian Oudard
  • 48,140
  • 25
  • 66
  • 69

5 Answers5

28

From Mozilla's documentation

<form name="form1" id="form1" method="post" autocomplete="off"
  action="http://www.example.com/form.cgi">
[...]
</form>

http://developer.mozilla.org/en/How_to_Turn_Off_Form_Autocompletion

Ryan Lanciaux
  • 5,965
  • 2
  • 37
  • 49
  • That did not work for me. But the following answer worked for me `http://stackoverflow.com/a/26156376/4601322` – BoCyrill Nov 02 '16 at 18:01
7

The autocomplete="off" method doesn't work for me. I realized firefox was injecting the saved password in the first password field it encountered, so the solution that worked for me was to create a dummy password field before the password update field and hide it. Like so:

<input type="password" style="display: none;" />
<input type="password" name="password_update" />
Jay Nielsen
  • 119
  • 1
  • 3
  • The hidden field is quite nice although its for FF only. Still the only solution if working with Angular. The [web-docu](https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion) does not work :-/ – LeO Sep 26 '17 at 06:50
2

Have you tried adding the autocomplete="off" attribute in the input tag? Not sure if it'll work, but it is worth a try.

Rob Rolnick
  • 8,519
  • 2
  • 28
  • 17
0

are all your input boxes set to type=password? That would do it. One of the things you can do, and I'm not at all sure that this is the best answer is to leave input box as an input type and just use javascript and onkeydown event to place stars in the input box instead of having the browser render it. Firefox won't pre-fill that.

As an aside, I have had to work on single-page web-apps and I absolutely hate it. Why would you want to take away the user's ability to bookmark pages? To use the back button?

George Mauer
  • 117,483
  • 131
  • 382
  • 612
0

Adding to this answer https://stackoverflow.com/a/30897967/1333247

This is in case you also have a User field in front of the password fields and want to disable autocompletion for it too (e.g. router web config, setting proxy User and Password).

Just create a dummy user field in front of the dummy password field to hide user name autocompletion:

<input type="text" style="display: none;" />
<input type="password" style="display: none;" />
<input type="password" name="password_update" />

Per the docs this is about the Login autocompletion. To disable the normal one (e.g. search terms completion), just use the

autocomplete="off"

attribute on the form or inputs. To disable both you need both, since the attribute won't disable Login autocompletion.

Jakub Fojtik
  • 681
  • 5
  • 22