Karl
Karl

Reputation: 956

Prevent autofill of passwords for all browsers

It's well documented that Chrome and Firefox ignore the standard autocomplete="off" attribute in html as they (Google) feel it wasn't being used correctly. They have even come up with workarounds and their own set of values for autofilling fields.

However, We need to prevent users passwords from being auto-filled for a website we're working on, and none of the suggestions put forward by Google appear to work.

The current situation on our website is that login names and passwords are stored by the browser, and so when a user visits the site and they're forced to login, their username and passwords are pre-populated in the relevant fields and they simply click the login button to login.

This has been deemed insecure, and while the infosec team are happy for the username to be pre-populated, they insist the password field is not.

To start with I tried adding the autocomplete="off" attribute to the password fields, but the password was still pre-populated. After some googling I found this link that shows Google decided to ignore this value and come up with a list of their own values for the autocomplete attribute...

Google ignores autocomplete="off"

They state that if we add our own, non-recognised value (such as autocomplete="please-dont-auto-fill-me") if shouldnt auto fill as it wouldnt know what that value is for.

However, I added something more meaningful - autocomplete="non-filled-value" - and it still populated the field. I've since tried a number of other things, such as renaming the password input control (removing the word "password" from the control name) etc and nothing seems to work. every time I load the login page, the password is pre-populated.

The issue I have is that my login form will be loaded on multiple browsers as different users from around the world login, and I need a solution that works for all browsers, not just Chrome.

Does anyone have any experience of this, and has a working solution for preventing fields being pre-populated/auto-filled that works cross browser? Everything I've tried (renaming fields, adding hidden fields, setting obscure autocomplete attribute values) fails to work, and whatever I try, the password is pre-populated.

Obviously, I have no control over the users actual browser settings and cant force them all to change their own personal settings.

Upvotes: 6

Views: 6006

Answers (3)

glennsl
glennsl

Reputation: 29126

As explained in this MDN article, autocomplete="off" will be ignored for password auto-fill, but autocomplete="new-password" is likely to work, though it carries additional semantic information:

If you are defining a user management page where a user can specify a new password for another person, and therefore you want to prevent autofilling of password fields, you can use autocomplete="new-password".

This is a hint, which browsers are not required to comply with. However modern browsers have stopped autofilling elements with autocomplete="new-password" for this very reason. For example, Firefox version 67 (see bug 1119063) stopped autofilling in this case; however, Firefox 70 (see bug 1565407) can suggest securely-generated passwords, but does not autofill a saved password. See the autocomplete compat table for more details.

Upvotes: 5

New approach

I know how frustrating it is to try all solutions and seeing user and password fields ignore them.

Unforturnately, I haven't found a straightforward way of doing this, but I have a workaround for avoiding user password fields getting autofilled.

The problem

The main problem is that if you set input type="password", browsers automatically try fo autofill the field with saved passwords and users for the webapp, and nothing seems to work in order to stop it.

The solution

My approach is to avoid setting input type="passoword", but making the field look like a password field.

The way I found to achieve this was to build a font composed only by discs, so when you type anything in the input field, it looks like a password field, but you will never be prompted with saved user and password credentials.

I've tested this solution on Chrome, Firefox and Microsoft Edge, please let me know if is something worong with other browsers.

I know the solution is awful, but seems to work.

Link to the font, made by me using Font Forge: https://drive.google.com/file/d/1xWGciDI-cQVxDP_H8s7OfdJt44ukBWQl/view?usp=sharing

Example

Browsers will not fill in the input elements because none of them is type="password"

Place the .ttf file in the same directory where you create the following html file:

<!DOCTYPE html>
<html>
    <head>
        <title>Font Test</title>
    </head>
    <body>
      <span>Name: </span><input type="text"/>
      <span>Password: </span><input class="disk-font" type="text"/>       
    </body>
    <style>
            @font-face {
                font-family: disks;
                src: url(disks.ttf);
            }
            .disk-font{
                font-family: disks;

            }
    </style>
</html>

Hope this is helpful, feel free to comment any issue.

Upvotes: 4

Victor Magosso
Victor Magosso

Reputation: 28

Actually, i've recently faced this issue, and a workaround which worked form me is just setting the value as an empty string on a method (can be onload, for example if the input is in your main screen). Would be something like:

let login = document.querySelector('#inputLogin');
let password = document.querySelector('#inputPassword');

function someFun () {
     login.value = '';
     password.value = '';
}

Also I've already tried to put autocomplete="false" but didn't work.

Upvotes: 0

Related Questions