Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

autocomplete ='off' is not working when the input type is password and make the input field above it to enable autocomplete

I have an form with autocomplete disabled but it does not works and makes the autocomplete to be enabled in firefox and higher version of chrome

<form method="post" autocomplete="off" action="">     <ul class="field-set">     <li>         <label>Username:</label>         <input type="text" name="acct" id="username" maxlength="100" size="20">     </li>     <li>         <label>Password:</label>         <input type="password" name="pswd" id="password" maxlength="16" size="20" >     </li>     <li>         <input type="submit" class="button" value="Login" id="Login" name="Login">     </li>     </ul> </form> 

When the type is changed from password to text it works in all browser. Can anyone help to solve this issue?

like image 728
user2594463 Avatar asked Jul 18 '13 09:07

user2594463


People also ask

How do I turn off autocomplete on password field?

Preventing autofilling with autocomplete="new-password" 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" .

Why autocomplete off is not working?

Chrome respects autocomplete=off only when there is at least one other input element in the form with any other autocomplete value. This will not work with password fields--those are handled very differently in Chrome.

Why autocomplete is not working in HTML?

The solution is simple and working perfectly in all browsers. Add disabled and autocomplete="off" attribute to the form fields( name, age, etc.) On Page Load enable the fields after few miliseconds.

Can I use autocomplete new password?

Just use autocomplete="new-password" at the confirmation input. And if you choose to generate a new password in the password input, the confirmation input gets filled with the same value instantly. Tested in chrome.


2 Answers

You can just make the field readonly while form loading. While the field get focus you can change that field to be editable. This is simplest way to avoid auto complete.

<input name="password" id="password" type="password" autocomplete="false" readonly onfocus="this.removeAttribute('readonly');" /> 
like image 144
sujivasagam Avatar answered Sep 20 '22 07:09

sujivasagam


When I faced the same problem I resolved by creating a temporary text box above the password field and hide it

like this,

<form method="post" autocomplete="off" action="">     <ul class="field-set">     <li>         <label>Username:</label>         <input type="text" name="acct" id="username" maxlength="100" size="20">     </li>     <li>         <label>Password:</label>         <input type="text" style="display:none;">         <input type="password" name="pswd" id="password" maxlength="16" size="20" >     </li>         ...     </ul> </form> 

It will make the username text field not to show any previously typed words in a drop down. Since there is no attribute like name, id for the input field <input type="text" style="display:none;"> it wouldn't send any extra parameters also.

I am Not sure this is a good practice, but it will resolve the issue.

like image 23
Arivarasan L Avatar answered Sep 22 '22 07:09

Arivarasan L