Disable Chrome Password Save in Javascript

Asked

Viewed 5,717 times

8

Would you have any way to disable the option to save password in Google Chrome, by Javascript or jQuery?

I mean the login password. When my client logs in appears to him the option to save password, and after he enable it always when he accesses the system he remains logged in. I want to disable this in any Browser.

  • Gustavo, what password? refers to password when logging into a website? Only in Chrome or other browsers?

  • The password to login. When my client logs in appears to him the option to save password, and after he enable it always when he accesses the system he remains logged in. I want to disable this in any Browser.

  • I gave an answer with a complementary method, see if it helps as extra protection.

6 answers

7


Reading the answer from Markus Olsson in Soen, the suggestion is to use the autocomplete HTML to tell browser not to save information:

<form id="loginForm" action="login.cgi" method="post" autocomplete="off">

You can read more documentation about this on MDN English. This link can be read (translated freely):

The easiest and simplest way to disable questions to write Forms and Passwords and prevent data from being written is to cache the browser history using the attribute autocomplete with the value "off".

Apparently IE11 decided to break that rule and ignore this behavior.

There are two more chances:

  • Do the name random input. Generated from the server side and saved to SESSION for example.

  • Login via Ajax and then instead of sending a form Ubmit, would send the password and clear the field without the browser noticing.

  • I already use this option and even so appears to my client the option to save password after logging in. I would like to disable this by javascript.

  • @Gustavo I understand you do not want to appear the browser message to save the authentication data. I believe that in this case the only solution is a login made via Ajax.

  • @Tuyoshivinicius, I believe I will have to do just that. Thank you very much for your help.

  • @Gustavo, I put two more ideas together

  • 1

    Eu já utilizo essa opção, @Gustavo, that’s why is essential that you provide all relevant details in your question.

6

This is a complementary and server-side response. I am posting as an additional option.

Advantage of the method: it respects the user name autocomplete, and only protects the password.

Using some server side language, you can change the name from the password field to a pseudo-random string, and use an Hidden field to store that string, thus:

<input type="text" name="usuario">
<input type="password" name="SYG2d7s6f1Sr874yYGJ4">
<input type="hidden" name="auxiliar" value="SYG2d7s6f1Sr874yYGJ4">

Thus, the password field (virtually) will never be the same, taking the effectiveness of what was previously saved under another name.

Then, in a language like PHP, just use it like this:

$auxiliar=$_POST['auxiliar']

$usuario=$_POST['usuario']
$senha=$_POST[$auxiliar]

Another complementary trick is to create two fields of the type password, some browsers understand this as probable form password reset, and do not save in this case (can hide one of them with CSS, for example).

  • 3

    Dude, fantastic! It’s a shame we still need to juggle options that some browsers offer, without having to disable them...

  • Only one addendum: I spent almost 2 hours to find out that I had two identical forms on one page. One was set to not complete, and the other, no. How was using Angularjs and ng-model, form fields without configuration filled in the configured form, since the ng-model were the same

2

2

Nothing of the above has worked, but I have created a simple solution.

Define the three inputs of the form, being two of the type "text" and insert a javascript function in the password field that in my case defined as "exchange()" and a field "Hidden":

input name="usuario_login" **type="text"** id="usuario_login" required
autofocus/>

input name="senha" required **type="text"** id="senha" **onkeyup="trocar()"**/>

input type="hidden" name="senha_login" id="senha_login" value="" />

Below the javascript function that will replace the character typed in the password field with "*" and transfer the typed to the Hidden field.

function trocar(){

  var tecla = event.keyCode;

  if(tecla == 8){

    document.getElementById('senha_login').value = document.getElementById('senha_login').value.substring(0 ,  document.getElementById('senha').value.length);

  }else{

    if(tecla != 9 & tecla != 13){

       document.getElementById('senha_login').value = document.getElementById('senha_login').value + document.getElementById('senha').value.charAt(document.getElementById('senha').value.length - 1);

       document.getElementById('senha').value = document.getElementById('senha').value.replace(document.getElementById('senha').value.charAt(document.getElementById('senha').value.length - 1), '*'); 

    } 
  }
}

Then just take the values in server language "ASP", "PHP" or other and validate.

0

I went through the same problem, today 10/09/2019 the only solution I found was this

put 2 false inputs before your input

<input class="hidden" type="text" style="display: none!important; visibility: hidden!important;" ></input>
<input class="hidden" type="password" style="display: none!important; visibility: hidden!important;" ></input>

-1

Basically, Chrome recognizes any form with only two inputs (being a text and another password) as a password field and records any data the user writes there. Then suggest to save the data.

I recommend using two password type inputs whenever asking for password confirmation. This makes the browser get confused.

<input type='password' name='senha' />
<input type='password' name='none' hidden />

Browser other questions tagged

You are not signed in. Login or sign up in order to post.