66

You might already know, that Safari has a nasty autofill bug where it fills email, username and password fields no matter if you set autocomplete="off" or not.

Here's a basic form:

<form action="/" method="post">
    <p>
        <label>E-mail</label>
        <input type="text" name="email" value="" />
    </p>
    <p>
        <label>Password</label>
        <input type="password" name="password" value="" />
    </p>
</form>

...Safari autofills those fields on page load like it should, job well done!

If you put autocomplete="off" to the fields and/or the form element, Safari still autofills those fields:

<form action="/" method="post" autocomplete="off">
    <p>
        <label>E-mail</label>
        <input type="text" name="email" value="" autocomplete="off" />
    </p>
    <p>
        <label>Password</label>
        <input type="password" name="password" value="" autocomplete="off" />
    </p>
</form>

Even this doesn't work:

<form action="/" method="post" autocomplete="off">
    <p>
        <label>E-mail</label>
        <input type="text" name="secretfield1" value="" autocomplete="off"/>
    </p>
    <p>
        <label>Password</label>
        <input type="password" name="secretfield2" value="" autocomplete="off" />
    </p>
</form>

...since Safari looks up those <label> elements if they contain words "E-mail", "Password" etc. and goes ahead with the autofill.

Aaaahhhhha!, I thought, and tried this:

<form action="/" method="post" autocomplete="off">
    <p>
        <label>%REPLACE_EMAIL_TITLE%</label>
        <input type="text" name="%REPLACE_EMAIL_NAME%" value="" autocomplete="off"/>
    </p>
    <p>
        <label>%REPLACE_PASSWORD_TITLE%</label>
        <input type="password" name="%REPLACE_PASSWORD_NAME%" value="" autocomplete="off" />
    </p>
</form>

...and replace %TAGS% with the real names using JavaScript. Safari autofill kicks in. No matter if you set a 10 second timeout on the replacement.

So, is this really the only option?

<form action="/" method="post" autocomplete="off">
    <p>
        <label>That electronic postal address we all use, but can't write the title here because Safari fills this with YOUR information if you have autofill turned on</label>
        <input type="text" name="someelectronicpostaladdress" value="" autocomplete="off"/>
    </p>
    <p>
        <label>A set of characters, letters, numbers and special characters that is so secret that only you or the user you are changing it for knows, but can't write the title here because Safari sucks</label>
        <input type="password" name="setofseeecretcharacters" value="" autocomplete="off" />
    </p>
</form>

I hope not?

UPDATE: @skithund pointed out in Twitter, that Safari is getting a 4.0.3 update, which mentions "Login AutoFill". Does anyone know if that update is going to fix this?

Jari
  • 749
  • 1
  • 6
  • 9

20 Answers20

51

The reason browsers are ignoring autocomplete=off is because there have been some web-sites that tried to disable auto-completing of passwords.

That is wrong.

And in July 2014 Firefox was the last major browser to finally implement the change to ignore any web-site that tries to turn off autocompleting of passwords.

One of the top user-complaints about our HTML Forms AutoComplete feature is “It doesn’t work– I don’t see any of my previously entered text.” When debugging such cases, we usually find that the site has explicitly disabled the feature using the provided attribute, but of course, users have no idea that the site has done so and simply assume that IE is buggy. In my experience, when features are hidden or replaced, users will usually blame the browser, not the website.

Any attempt by any web-site to circumvent the browser's preference is wrong, that is why browsers ignore it. There is no reason known why a web-site should try to disable saving of passwords.

  • Chrome ignores it
  • Safari ignores it
  • IE ignores it
  • Firefox ignores it

At this point, web developers typically protest “But I wouldn’t do this everywhere– only in a few little bits where it makes sense!” Even if that’s true, unfortunately, this is yet another case where there’s really no way for the browser to tell the difference. Remember, popup windows were once a happy, useful part of the web browsing experience, until their abuse by advertisers made them the bane of users everywhere. Inevitably, all browsers began blocking popups, breaking even the “good” sites that used popups with good taste and discretion.

What if I'm a special snowflake?

There are people who bring up a good use-case:

I have a shared, public area, kiosk style computer. We don't want someone to (accidentally or intentionally) save their password so the next user could use it.

That does not violate the statement:

Any attempt by any web-site to circumvent the browser's preference is wrong

That is because in the case of a shared kiosk:

  • it is not the web-server that has the oddball policy
  • it is the client user-agent that has the oddball policy

The browser (the shared computer) is the one that has the requirement that it not try to save passwords.

The correct way to prevent the browser from saving passwords
is to configure the browser to not save passwords.

Since you have locked down and control this kiosk computer: you control the settings. That includes the option of saving passwords.

In Chrome and Internet Explorer, you configure those options using Group Policies (e.g. registry keys).

From the Chrome Policy List:

AutoFillEnabled

Enable AutoFill

Data type: Boolean (REG_DWORD)

Windows registry location: Software\Policies\Chromium\AutoFillEnabled

Description: Enables Chromium's AutoFill feature and allows users to auto complete web forms using previously stored information such as address or credit card information. If you disable this setting, AutoFill will be inaccessible to users. If you enable this setting or do not set a value, AutoFill will remain under the control of the user. This will allow them to configure AutoFill profiles and to switch AutoFill on or off at their own discretion.

Please pass the word up to corporate managers that trying to disable autocompleting of password is wrong. It is so wrong that browsers are intentionally ignoring anyone who tries to do it. Those people should stop doing the wrong thing.™

Put it another way

In other words:

  • if the users browser
  • mistakes "Please enter the name of your favorite maiden name's first color." for a new password
  • and the user
  • doesn't want their browser
  • to update their password,
  • then they
  • will click Nope

enter image description here

  • if i want to save my HIPPA password: that's my right
  • if i want to save my PCI password: that's my right
  • if i want to save the "new password for the user": that's my right
  • if i want to save the one-time-password: that's my right
  • if i want to save my "first color's favorite maiden" answer: that's my right.

It's not your job to over-rule the user's wishes. It's their browser; not yours.

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
  • 9
    Passwords, maybe, but why do they so strongly enforce such a lack of regard for standards on username/email fields? It causes real problems for things like editing profiles. – Tim Rodham Apr 24 '15 at 09:27
  • 2
    @TimRodham The reason all browsers starting ignoring `autocomplete=off` is because some web-sites showed they could not be trusted to use `autocomplete=off` responsibly. Web-sites tried to disable autocomplete of usernames and passwords, in violation of the user's wishes. Few rotten apples and all that. I suggest if you don't want the browser to auto-complete a username field, you click *"no"* when it asks you if you want it to remember the contents of the username field. – Ian Boyd Apr 24 '15 at 21:00
  • Completing to the snowflake case. If you have a public computer just change every shortcut to `(...)\chrome.exe" -incognito` this will always launch the browser in incognito mode. That works incredible well, as soon they leave the computer all history, cookies and sessions are erased. – Vitim.us Jul 04 '15 at 01:40
  • 26
    What about the use case where I have an account manager where I as an admin have access to the profiles of other people's account? When I pull up their account page which has a username and password, it auto-fills my email when I want it to stay the user's email! Safari is removing valid data in this auto-complete effort that is completely inappropriate in this use case and is not a browser issue (I want my account username and password auto-filled on the login form, but not on an account editing form when I'm editing someone else's account!) – Kudit Dec 01 '15 at 18:06
  • 1
    @Gujamin If you want Safari to not auto-populate form fields, then *you* need to tell *your* browser not to auto-populate on *your* machine. That is *your* preference, and you should set *your* preference according to *your* preferences. ([Steps to disable Safari from auto-filling forms](http://smallbusiness.chron.com/disable-autocomplete-apple-safari-43008.html)). Short version: the web-site shall not override *my* preference. – Ian Boyd Dec 01 '15 at 23:45
  • 7
    @IanBoyd it's preposterous that I should enable autofill on one page of the site but then have to modify the browser preferences for a different page of the site! There would NEVER be the case where I would want my account username and password autofilled on a sub-user edit form. – Kudit Dec 02 '15 at 19:09
  • A much better example is that you have site admins who can change peoples usernames and reset their passwords. Unfortunately, if they try to edit a user, it autofills and tries to reset the username and password to be their own. I want admins to be able to have their passwords remembered, I don't want those usernames and passwords to be applied to other users. – rjmunro Dec 17 '15 at 13:02
  • 5
    @IanBoyd: **my** preference is for FormA (the login form) to autofill my information, but FormB, which has autofill turned off, to (gasp, horrors!) **NOT** autofill my information, because FormB is for adding new users. This absolutely SHOULD be adjustable on the form-design level, and the fact that browsers purposely disobey those settings is, frankly, insane. – Martha Apr 07 '16 at 21:04
  • 1
    @Martha The problem was that some security auditors, and government regulations, demanded that FormA (the login form) disable autofilling of your information. The developer, [who is not allowed to explain their opinion of that requirement](https://cdn.meme.am/instances/400x/58919540.jpg), has to rely on the browser vendor to enforce the right thing. If you can think of a middle ground where nobody is able to disable form filling where ***i*** want it enabled, but disable form willing where ***you*** want it disabled, you can be rich! – Ian Boyd Apr 08 '16 at 01:19
  • 3
    @IanBoyd: I think we have different ideas of "the right thing". In *my* world, that means that if the form says "don't autofill me", then the browser must not autofill it. If the form is badly designed, that's the designer's problem; short of developing ESP, the browser CAN'T fix it, and therefore must not try, because the downside of getting it wrong (giving unauthorized access to private information) is much, much, much worse than the downside of obeying the form (I have to re-type my password, boo hoo hoo, woe is me). – Martha Apr 08 '16 at 04:16
  • 2
    @Martha It's not the designer's problem: it's the user's problem - it's *my* problem. You cannot leave that decision up to the designer; because the designer might try to turn off autofilling. So we are where we are: bad designers (forced by dumb managers) turn off autofilling, and so every browser now ignores requests to turn off autofilling. You may not like it, but we are where we are, and it's not going to change. I have much less of a problem telling a government security auditor where to go. Not every developer, bank, or hospital, has that luxury. – Ian Boyd Apr 10 '16 at 00:20
  • 3
    The logic that it should be up to the user is deeply flawed, as 99.99% of users will never change their settings. It's like saying that a designer should not change the user agent's CSS background color for pages. There are many cases where the form has a _better default_ than the typical user default. Namely, as @rjmunro and Gujamin mentioned, admin sections. Where a username / password is NOT a login form, and will have different values for every user you're managing. Browser makers failed in their foresight here. – Matthew Dean Apr 26 '16 at 22:26
  • 1
    @MatthewDean I agree with you. Browser vendors are throwing the baby out with the bath water. But as long as HIPPA exists: we are where we are. A workaround would be to ensure that the text box on the *"reset user's password"* page is `type=text` rather than `type=password`. That way you reserve password entry for for users entering passwords (and not when it's IT changing someone else's password). If you can figure out an alternative that prevents HIPPA disabling password saving, share it! – Ian Boyd Apr 27 '16 at 15:57
  • 1
    @IanBoyd type=text doesn't disable the "save password" prompt, unfortunately. :/ I got to this thread because of this very problem. Safari was (is) essentially overwriting every user's user name and password when admins went to update other settings. NOT GREAT. – Matthew Dean May 04 '16 at 17:48
  • 2
    We have a situation where Safari is autofilling login details into a admin account editing page. I think this is a legitimate use case of "No auto-fill". – ioquatix Jun 23 '16 at 01:35
  • The admin account editing page is a good use case in principle, but it is a very bad idea to autocomplete an admin username and password that gives full access to other users' information and rights... – Samuel Bradshaw Feb 02 '17 at 04:06
  • Browsers have completely got the standard wrong, I'd say they're being lazy in dealing with the problem in the simplest manner they see possible. That doesn't mean it's the correct/best - as noted by @Gujamin with a perfectly valid use case. Browsers ignoring the standard because of user complaints is WRONG! Browsers should make a better attempt at determining when to autofill/autocomplete, or their ID10T errors instead of diminishing the standard. Worst for me is on custom street search/address forms?? – Tjad Clark Feb 15 '19 at 06:40
  • I mean really! A browser could prompt the user regarding autofill where it thinks it's supposed to override autofill attribute instead of just overriding the intention of the site developer. Black listing instead of white listing. – Tjad Clark Feb 15 '19 at 06:43
  • @TjadClark That's what browsers do now - they prompt the user regarding autofill where it thinks it's supposed to autofill (see the screenshot attached to the answer above). – Ian Boyd Feb 15 '19 at 15:29
  • - Not on the phones I've been using. – Tjad Clark Mar 01 '19 at 06:13
  • Here's a case: I want to disable Safari autofill bec. of how long it takes. On my advanced search form (with dynamically added rows), Safari autofill delays the entry of text, by 1 to 2 seconds, and sometimes beachballs the browser for longer. No idea why it takes so long, but if I disable all autofill options in the Safari prefs, there is no delay. Note, after entering the 1st character, the delay goes away. I may need to resort to adding a hidden label to tell Safari this isn't a name field, because after the delay from clicking the field, a user icon shows up on the right side of the field. – hepcat72 Aug 17 '21 at 15:25
  • @hepcat72 *"In macOS, go back to the Passwords tab and uncheck Autofill User Names and Passwords at top."* – Ian Boyd Aug 17 '21 at 23:32
  • @Ian Boyd - I'm developing a website. I don't want users to encounter a laggy form if they have autofill enabled in Safari. I know *I* can change *my* browser settings, but aside from that, I *want* autofill on other sites. Thus the place I want to disable it is in the form itself. – hepcat72 Aug 17 '21 at 23:46
  • @hepcat72 The issue is that if you disabled autofill on your website: then fields might not auto-fill. That's a user's preference, not the web-sites. That is why all browsers ignore attempts to circumvent the user's preference. If it is the user's preference: they can turn it off. – Ian Boyd Aug 18 '21 at 14:08
  • @IanBoyd - The problem is that not only is the autofill execution inaccurate (suggesting phone number entries in a scientific database's search term field, for which there is no phone number DB field to search), it also is terribly slow, preventing text entry for multiple seconds. And by the way, I don't want to disable it for the entire page - I just want to disable it for those search term fields. If it didn't have these problems, there would be no need to disable it. – hepcat72 Aug 18 '21 at 14:16
  • @IanBoyd - I would prefer it if it didn't have this issue. It would be totally cool if it suggested previously entered terms and did so without noticeably affecting form performance - but since it is completely useless in this case, and in fact detrimental to the usage of my site, disabling is a perfectly acceptable path to take. – hepcat72 Aug 18 '21 at 14:21
  • @IanBoyd - In other words, I'd agree with you if it actually worked correctly. Your stance would only be correct if autofill was bug free and ran efficiently. If every time it ran, it suggested useful entries without slowing down form performance, then I'd be on your side 100%. Though I've been a programmer for far too long to ever be that confident in any code. – hepcat72 Aug 18 '21 at 14:46
  • @hepcat72 I hear your concerns. But unfortunately too many developers, or managers, or security experts, thought it would be a good idea to blanket turn off auto-filling of fields; including passwords. And that unfortunately means there is no way for a browser to know if your desire to turn off auto-filling is a valid choice or not. For example, if you turned off auto-filling of the search box for a scientific database: that might mean that auto-filling of the search box might not work for me. I've never seen a browser lock up trying to auto-fill a text box. Sounds like a Safari issue. – Ian Boyd Aug 18 '21 at 14:58
  • Incidentally, I found a work-around. You can in effect, "turn off" (sort of) Safari autofill for the search text field by adding a placeholder attribute that doesn't imply any of the autofill categories that are supported by Safari autofill. I supplied "search term" as my placeholder and now Safari autofill doesn't introduce lag or make phone number (or any other) suggestions. I'd tried numerous other suggested strategies that all failed. – hepcat72 Aug 19 '21 at 17:55
38

I had the same problem. And though my solution is not perfect, it seems to work. Basically, Safari seems to look for an input field with password and username and always tries to fill it. So, my solution was to add a fake username and password field before the current one which Safari could fill. I tried using style="display: none;" but that did not work. So, eventually, I just used

<input id="fake_user_name" name="fake_user[name]" tabindex="-1"
               style="display:none;" type="text" value="Safari Autofill Me"

and this hid the input field out of sight and seemed to work fine.

I did not want to use JavaScript but I guess you could hide it with JavaScript.

Now Safari never autocompletes my username and password fields.

Vega
  • 27,856
  • 27
  • 95
  • 103
Richard perris
  • 511
  • 1
  • 6
  • 15
  • 5
    wow, thanks, it works, bless! Safari desktop autofilling form no more. here is the code prepended before the actual input field `` – manitu May 08 '14 at 09:13
  • 1
    Note that I used `` and that worked for me. – usumoio Jul 12 '14 at 03:22
  • 1
    Just saying, why not use only `style="display:none"` seems cleaner IMO, Its not going to show up miraculously bro lmao. – Neo Jul 21 '14 at 06:22
  • 4
    At least on Mac Safari ignores input boxes with `style="display:none"` and chooses another victim for autofill. If only software is so smart when it is really needed... – Michal Aug 22 '14 at 13:02
  • The problem with this solution is it breaks the tabindex, so it's both annoying for a regular user (tabbing from username doesn't drop you into the password field like it's supposed to) as well as being an accessibility issue. – mAAdhaTTah Aug 13 '15 at 23:00
  • 5
    @mAAdhaTTah You can disable tabbing on the fake inputs with `tabindex="-1"` – falsarella Jan 18 '16 at 13:04
20

Fix: browser autofill in by readonly-mode and set writable on focus

 <input type="password" readonly onfocus="this.removeAttribute('readonly');"/>

(focus = at mouse click and tabbing through fields)

Update: Mobile Safari sets cursor in the field, but does not show virtual keyboard. New Fix works like before but handles virtual keyboard:

<input id="email" readonly type="email" onfocus="if (this.hasAttribute('readonly')) {
    this.removeAttribute('readonly');
    // fix for mobile safari to show virtual keyboard
    this.blur();    this.focus();  }" />

Live Demo https://jsfiddle.net/danielsuess/n0scguv6/

// UpdateEnd

Explanation: Browser auto fills credentials to wrong text field?

Ok, you just noticed that:

Safari autofill kicks in. No matter [what the fields are named] @Jari

and there's an assumption that:

Safari seems to look for an input field with password and username and always tries to fill it @user3172174

Sometimes I notice this strange behavior on Chrome and Safari, when there are password fields in the same form. I guess, the browser looks for a password field to insert your saved credentials. Then it autofills username into the nearest textlike-input field , that appears prior the password field in DOM (just guessing due to observation). As the browser is the last instance and you can not control it,

sometimes even autocomplete=off would not prevent to fill in credentials into wrong fields, but not user or nickname field.

This readonly-fix above worked for me.

dsuess
  • 5,219
  • 2
  • 22
  • 22
  • Having used this fix last year, it now seems to cause more problems than it fixes, as Chrome no longer sends the form field when you use this code. – Tim Rodham Sep 16 '15 at 10:26
  • 1
    @TimRodham: Readonly fields may not be send to server. That's correct, as it assumes, the uses could not enter data. When user enters the input field, it is not readonly anymore and will be send. Does this explanation helps you out? Otherwise please set up a litte code example in stackoverflow or fiddle so I can check this issue. – dsuess Sep 16 '15 at 14:37
  • 2
    Safari enables autofill when you focus on the field. – Peter DeWeese Oct 13 '16 at 13:48
  • It doesn't work now, input is filled once it's clicked / focused. – Eduardo Mar 20 '23 at 07:20
17

Adding the CSS to the input will hide the Safari button pseudo-element and users will not be able to use autocomplete:

input::-webkit-contacts-auto-fill-button, 
input::-webkit-credentials-auto-fill-button {
  visibility: hidden;
  position: absolute;
  right: 0;
}
MobiDevices
  • 887
  • 8
  • 22
8

Just put search into the name, Safari will ignore the field for autofill.

<input type="password" name="notsearch_password">
bokorben
  • 161
  • 1
  • 8
7

This question has already been successfully answered, but as of today's date, the solution didn't work for me without making some oddly particular changes - so I'm noting it here as much for my own reference if I decide to come back to it as for everyone else's.

  • The fake input needs to be after the real email input in the dom.
  • The fake input requires a fake label.
  • The fake label cannot be absolutely positioned.
  • Can't use display, visibility or opacity to hide the fake elements.

The only solution I found was to clip the visibility of the fake elements with overflow: hidden.

<label for="user_email">Email</label>
<input autocomplete="off" type="text" value="user@email.com" name="user[email]" id="user_email">
<!-- Safari looks for email inputs and overwrites the existing value with the user's personal email. This hack catches the autofill in a hidden input. -->
<label for="fake_email" aria-hidden="true" style="height: 1px; width: 1px; overflow: hidden; clip: rect(1px, 1px, 1px, 1px)">Email</label>
<input type="text" name="fake[email]" id="fake_email" style="height: 1px; width: 1px; overflow: hidden; clip: rect(1px, 1px, 1px, 1px)" tab-index="-1" aria-hidden="true">

For the record, the particular case this hack came in useful for was one where an admin is editing the profile of other users and Safari was replacing the email of the user with the email of the admin. We've decided that for the small (but frustrating) amount of support requests that this Safari 'feature' creates, it's not worth maintaining a hack that seems to need to evolve as Safari tightens up on it, and instead provide support to those users on how to turn off autofill.

dontwakemeup
  • 93
  • 1
  • 6
6

After scanning through Apple's Safari HTML pages and not finding anything on auto complete, I did some searching and thinking.

After reading a (mildly) related question on Apple discussions, I remembered that the default is to not allow remembered passwords, etc (which can be enabled in iDevice system settings, or at the prompt). Since Apple has moved this feature out of the browser and into their (proprietary, i)OS (screen shots on this article), I believe they are ignoring the HTML form/field property entirely.

Unless they change their mentality as to this feature, as I'm sure this is their expected behavior, on their locked down devices, I would work under the assumption that this isn't going away. This is probably different for native iOS apps. Definitely keep the form autocomplete="off" and hopefully they'll one day get back to the HTML5 standard for the feature.

I know this doesn't include any work around, but I think if you come to terms with it being a non-browser 'feature' on iDevices, it makes sense (in an Apple kind of way).

Eric McCormick
  • 2,716
  • 2
  • 19
  • 37
  • 1
    This applies to Chrome and Chromium as well. See this [bug report](https://code.google.com/p/chromium/issues/detail?id=370363#makechanges). It just seems like you have an Apple axe to grind. – CadentOrange Aug 13 '14 at 09:51
  • 1
    I hadn't run into it in Chrome, but then I suspect they handle it slightly differently too. No axe, I like Apple's products as they usually do what's expected. I'm just leery of any individual vendor applying their own rules to supercede the W3's standards. – Eric McCormick Aug 13 '14 at 15:47
  • Uh wow. Safari seems to enable autofill as soon as the placeholder contains a combination of `user` and `name`. like "user name" or "username" both trigger autofill. "name" does not. autocomplete="off" has no effect. This is 6 years later. Thanks for the fish, apple. – st-h Nov 21 '20 at 12:44
5

I can't believe this is still an issue so long after it's been reported. The above solutions didn't work for me, as safari seemed to know when the element was not displayed or off-screen, however the following did work for me:

<div style="position:absolute;height:0px; overflow:hidden; ">
  Username <input type="text" name="fake_safari_username" >
  Password <input type="password" name="fake_safari_password">
</div>

Hope that's useful for somebody!

Ben
  • 4,707
  • 5
  • 34
  • 55
3

I have also been bitten by Safari's weird default autocomplete behaviour, but rather than completely disable it, I managed to make it work for me by following the guidelines at https://www.chromium.org/developers/design-documents/form-styles-that-chromium-understands.

Specifically, I put autocomplete="username" on the username field and autocomplete="password-current" on the password field. This tells the browser which fields to autofill, rather than having it guess, and it fixed autocomplete for my use case.

This approach works for both "email first" login forms (password field not immediately visible, eg Google login) as well as conventional login forms with both username and password fields visible.

S M
  • 8,155
  • 3
  • 35
  • 36
1

My issue: I have a section in an admin area that allows users to set all language values, some of which contain the words "password", "email", "email address" etc. I don't want these values to be filled with the user's details, they are for creating translations into another language. This is then a valid exception to the "circumvent the browser's preference" mentioned.

My solution: I simply created alternate names:

$name = str_replace('email','em___l',$name);
$name = str_replace('password','pa___d',$name);
<input type="text" name="<?=$name?>" id="<?=$name?>" />

Then when the form is posted:

foreach($_POST as $name=>$value) {
    $name=str_replace('em___l','email',$name);
    $name=str_replace('pa___d','password',$name);
    $_POST[$name]=$value;
}

This is the only method that worked for me.

vendo
  • 13
  • 1
  • 4
1

For me, this problem was very sharp. But only about password autofill.

Safari generates it's 'strong' password into a sign-in form. Not a sign-up form. Only the user's password will work in sign-in form, not generated. Obvious.

I made a few tries to disable it with advice from here. But without results.

BTW. It was easy to fix with angular binding. So. This code will work 4 you only in case of using Angular2+ in the web layer.

<mat-form-field appearance="fill">
  <mat-label>Enter your password</mat-label>
  <input #pwd 
         matInput
         [type]="pwd.value.length === 0 ? 'text': 'password'"
         formControlName="passwordCtrl"
  required>
</mat-form-field>

Attribute [type] use one side binding with "[", "]". And automatically set value by the condition "(condition) ? option1: option2". If no symbols in the input - then the type is 'text'.

And not very 'clever' Safari browser doesn't perform autofill. So. Goal reached. Autofill disabled.

After more than 1 symbol in the input field. Type changes to 'password' very fast. And the user has no idea about something that happened. The type of the field is 'password'.

Also, it works with (keypressed) Event. Or using [(ngModel)]="pwd" instead of #pwd. And access by reactive forms.

But the basic thing that solved the problem for my cases - angular binding.

1

I came up with a similar solution to Nikita Danilov's, but for vanilla JavaScript instead of Angular.

Basic principle is for the field to start off as a generic type like "text" or "number", then switch to "password" or "email" where appropriate. onkeydown is a good event to bind here - should work on Desktop and Mobile.

Example:

<input 
  type="text"
  name="password" 
  id="password"
  autocomplete="off"
  onkeydown="this.setAttribute('type','password')"
>

While I understand the points made against introducing this behaviour, I think many make an assumption that the context of a password field is always a login / registration form that the end-user interacts with. In some cases e.g. where passwords or other details are being set on admin panels, by users other than the end-user, I believe it is justified to avoid engaging the browser's autofill, as it is linked against the current user's personal data. In such case the current user, is not the end-user.

st4wik
  • 476
  • 1
  • 4
  • 5
0

You can try this variant. It works for me. If you change field value once, Safari will change it again. If user clicked at this field, after this the value wouldn't be changed by Safari automatically.

  $.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());
        if($.browser.chrome){
            $.browser.safari = false;
        }

        var isChanged=false;

        $('#Email').change(function () {
            if ($.browser.safari && !isChanged) {
                $('#Email').val('@Model.Email');
            }
        });

        $('#Email').click(function () {
            if ( $.browser.safari && !isChanged) {
                isChanged = true;
            }
        }); var isChangePassword = false;
    $('#OldPassword').change(function () {
        if ($.browser.safari && !isChangePassword) {
            $('#OldPassword').val('');
        }
    });

    $('#OldPassword').click(function () {
        if ($.browser.safari && !isChangePassword) {
            isChangePassword= true;
        }
    });
0

Better than use JS to clear content - simply fake password field:

<input type="text" name="user" />
<input fake_pass type="password" style="display:none"/>
<input type="password" name="pass" />

A password type doubled put the browser in incertitude so it autocompletes only user name

fake_pass input should not have name attribute to keep $_POST clean!

falsarella
  • 12,217
  • 9
  • 69
  • 115
bortunac
  • 4,642
  • 1
  • 32
  • 21
  • Fake field already [covered by Richard](http://stackoverflow.com/a/23016234/1064325). Note that `display: none;` won't fool the browser. – falsarella Jan 18 '16 at 13:11
0

It seems the browser programmers think they know more than the website writers. While it's sometimes handy to allow the user to save passwords, there are other times when it's a security risk. For those times, this workaround might help:

Start by using a conventional text input, instead of a 'password' type.

Password: &nbsp <input type="text" id="fkpass" name="bxpass" class="tinp" size="20" />

Then - if you wish - set the focus to the input field.

<BODY onLoad="fitform()">

Put the JS at the end of the page.

<script type="text/javascript">
document.entry.fkpass.focus();
function fitform() {
document.getElementById('fkpass').autocomplete = 'off';
}
</script>

Now you have a conventional form field. What good is that?
Change the CSS style for that input so it uses a font that is all 'bullets' instead of characters.

<style type="text/css">
@font-face { font-family: fdot; src: url('images/dot5.ttf'); }
@font-face { font-family: idot; src: url('images/dot5.eot'); }
@font-face { font-family: wdot; src: url('images/dot5.woff'); }
@font-face { font-family: w2dot; src: url('images/dot5.woff2'); }
.tinp { font-family: fdot, idot, wdot, w2dot; color: #000; font-size:18px; }
</style>

Yes, you could 'tidy up' the code, and add .svg to it.

Either way, the end result is indistinguishable from the 'real' password input, and the browser won't offer to save it.

If you want the font, it's here. It was created with CorelDraw and converted with an online webfont conversion utility. (dot_webfont_kit.zip 19.3k)

I hope this helps.

imillard
  • 1
  • 1
  • 3
    This isn't good, security-wise. The `type="password"` gives user an additional security layer. – falsarella Jan 18 '16 at 13:15
  • Browser programmers think for the whole global user base, a website writer thinks only for the users of their particular web site. Having seen how immensly clueless website writers can be, I am completely confident that the browser programmers can be trusted on this. :) – Torben May 05 '21 at 06:42
0

Remove <form> element. To keep form behavior you can listen keypress event for input fields to handle enter key pressed. Just in case I removed input type="submit" too. You can use button type="button".

Ikrom
  • 4,785
  • 5
  • 52
  • 76
0

The CSS display: none solutions mentioned here did not work for me (October 2016). I fixed this issue with JavaScript.

I don't mind the browser remembering passwords, but wanted to prevent a bad autofill. In my case, a form with a password field and no associated username field. (User edit form in Drupal 7 site, where the password field is required only for some operations.) Whatever I tried, Safari would find a victim field for the username of the autofilled password (the field placed visually before, for instance).

I'm restoring the original value as soon as Safari does the autofill. I'm trying this only for the first 2 seconds after page load. Probably even lower value is OK. My tests showed the autofill happens around 250 ms after page load (though I imagine this number depends a lot on how the page is constructed and loaded).

Here's my JavaScript code (with jQuery):

// Workaround for Safari autofill of the e-mail field with the username.
// Try every 50ms during 2s to reset the e-mail to its original value.
// Prevent this reset if user might have changed the e-mail himself, by
// detecting focus on the field.
if ($('#edit-mail').length) {
  var element = $('#edit-mail');
  var original = element.attr('value');
  var interval = setInterval(function() {
    if ($(document.activeElement).is(element)) {
      stop();
    } else if (element.val() != original) {
      element.val(original);
      stop();
    }
  }, 50);
  var stop = function() {
    clearTimeout(timeout);
    clearInterval(interval);
  }
  var timeout = setTimeout(function() {
    clearInterval(interval);
  }, 2000);
}
François
  • 1,831
  • 20
  • 33
0

I had the same problem suddenly in a SPA with React in Mobile Safari 10.3.1

I do not need any tricky workarounds before in all tested browsers, even Mobile Safari IOS 10.2

But since 10.3.1 username or password will be filled in fields mentioning the words 'password','email','username' in any forms after login with active remember option. It seems that the rendered DOM-Tree is 'analyzed' using a full text search and then the user agent fill in data without respecting any autocomplete="off" setting. Happens funnyli also on placeholder text for a field. So you must be very carful with naming, when you don't want to have prefilled username or password in places where this data is not useful.

The only solution after hours of investigating was the solution here posted too. Provide a input field named "email" and hideout the containing div with height: 0px, overflow: hidden.

user767644
  • 31
  • 4
0

You can disable it by adding this attribute to password input

autocomplete="new-password"
Mohamad Hamouday
  • 2,070
  • 23
  • 20
0

Safari offers autocomplete if there is a word "username" inside of a label.

There are 2 solutions I found to prevent this:

  1. Adding the word "search" to the field's name (label and input)
  2. Replace the label's text character with its Unicode equivalent. For example: replace "a" with "\u0430".