Stop browser from auto filling the form username and password fields
Asked Answered
E

6

17

In the Chrome browser, I have saved the username and the password.

Now, if I navigate to some other form and it contains the username and password for some other stuff, the one I saved is auto-populated here.

How can I stop this?

Excellency answered 14/5, 2014 at 6:15 Comment(2)
possible duplicate of Is autocomplete="off" compatible with all modern browsers?Gelid
@koala_dev similar questions but not equalSelene
U
29

When autocomplete=off would not prevent to fill in credentials, use following -

fix browser autofill in: readonly and set writeble on focus (click and tab).

 <input type="password" readonly onfocus="this.removeAttribute('readonly');" onblur="this.setAttribute('readonly','');"/>
Untraveled answered 11/5, 2016 at 5:45 Comment(3)
that one did work. but it is very strange, that there is no support for this if I need to set password for some other stuff.Knapp
After hours & hours of searching finally I've found a working solution to prevent the form from being auto-filled by either the browser or 3rd party password managers. Thank you!Heartworm
I added an onblur handler; otherwise in FF 71, when you revisit the field it prompts you.Nysa
C
12

For Fire fox browser use this:

<input type="text" name="prevent_autofill" id="prevent_autofill" value="" style="display:none;" />
<input type="password" name="password_fake" id="password_fake" value="" style="display:none;" />
<input type="password" name="password" id="password" value="" />

For Chrome browser: use autocomplete="new-password"

Circumlocution answered 24/5, 2017 at 4:47 Comment(1)
autocomplete="new-password" also work for Firefox now (version 77.0.1)Gravettian
U
7

Please refer to the following:
https://www.chromium.org/developers/design-documents/create-amazing-password-forms and https://www.chromium.org/developers/design-documents/form-styles-that-chromium-understands

Try the following :

<form id="login" action="signup.php" method="post">
    <input type="text" autocomplete="username">
    <input type="password" autocomplete="new-password">
    <input type="password" autocomplete="new-password">
    <input type="submit" value="Sign Up!">
</form>
Uncritical answered 3/4, 2019 at 6:7 Comment(6)
The auto-complete flag doesn't stop the password manager for prompting to fill the username.Nysa
@LawrenceDol Which browser are you using?Uncritical
Firefox, current.Nysa
Have you tried the answer below by @Raymond Morphy `<input type="text" name="prevent_autofill" id="prevent_autofill" value="" style="display:none;" /><input type="password" name="password_fake" id="password_fake" value="" style="display:none;" /><input type="password" name="password" id="password" value="" /> My comment is relevant for the Chrome browser as the Question was for the chrome browser :)Uncritical
No, because I used the readonly on/off method.Nysa
PS, there's really no legitimate SO answer that is for "Chrome only"; such an answer is useless to the vast majority who don't control the client's browser.Nysa
S
3

Simple: there's an HTML5 attribute called autocomplete.

Just set it to off.

<input autocomplete="off"/>
Subminiature answered 2/7, 2014 at 17:24 Comment(3)
This does not reliably work in Firefox. There's some discussion here https://mcmap.net/q/549028/-disable-firefox-39-s-auto-fillDwt
When you make your browser remember your credentials, it will automatically fill the password trying to help you, even with autocomplete="off". The readonly answer from AK Square Infomedia does work for those cases. Great for update profile forms where you usually only want the password sent through if it's changing.Arezzini
This also does not work in Chrome. Not sure why they add such nice and useful features to the HTML spec if the browsers don't bother to implement them.Enumeration
M
0
<textarea required="required" autocorrect="off" autocapitalize="off" name="username" class="form-control" placeholder="Your username"  rows="1" cols="20" wrap="off"></textarea>
<textarea required="required" autocorrect="off" autocapitalize="off" name="password" class="form-control password" placeholder="Your password"  rows="1" cols="20" wrap="off"></textarea>
@font-face {
  font-family: 'password';
  src: url('css/font/password.woff2') format('woff2'),
       url('css/font/password.woff') format('woff'),
       url('css/font/password.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

textarea.form-control {
  overflow:hidden;
  resize:none;
  height:34px;
}

textarea.form-control.password:valid {
  font-family: 'password';
}

Notes

  1. Textarea prevent autofill
  2. wrap=off/overlow=hidden/rows=1 force one-line display
  3. the required pseudo css make the placeholder works
  4. You'll probably need some "prevent eventKey=13 / submit" thing
  5. Works fine under ffox/chrome/iOS

In the end, it end up been a freaking webshit sum of hacks (but it works)

Meander answered 17/11, 2021 at 22:47 Comment(0)
S
-1

First try to set the password field as

autocomplete="new-password"

The above solution should stop auto filling of both username & password

Note: Sometime setting up autocomplete="off" on username & password may not work

Soho answered 22/2, 2021 at 13:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.