skip to Main Content

I have an input for getting password from user :
<input name="Password" id="Password" required/>
in most devices browser will try to autocomplete the password input ( based on saved passwords ),
but lets say we don’t want this behavior , **so how could we turn off autocomplete for an input? **

after searching and trying to turn off autocomplete found this solution,
set attribute autocomplete to off :
<input name="Password" id="Password" required autocomplete="off"/>
but it didn’t work, when page loads this will happen , i tried JavaScript too but it didn’t worked neither
$("#Password").val('')

2

Answers


  1. The solution for Chrome is to add autocomplete="new-password" to the input type password. Please check the example below.

    Example:

    <form name="myForm"" method="post">
       <input name="user" type="text" />
       <input name="pass" type="password" autocomplete="new-password" />
       <input type="submit">
    </form>

    Chrome always autocomplete the data if it finds a box of type password, just enough to indicate for that box autocomplete = "new-password".

    Note: make sure with CTRL + F5 that your changes take effect. Many times, browsers save the page in the cache.

    Login or Signup to reply.
  2. There are 3 ways you could do this:-

    1. Add an attribute for the input field i.e, autocomplete = "off"

    Example:-

    <form>
       <input type="text" />
       <input type="password" autocomplete = "off"/>
       <input type="submit">
    </form>
    1. Add an attribute for the entire form i.e, autocomplete = "off"

    Example:-

    <form method="post" autocomplete="off">
       <input type="text" />
       <input type="password" autocomplete = "off"/>
       <input type="submit">
    </form>
    1. If the above 2 didn’t work then, set autocomplete = "new-password" to the input field. This should definitely prevent the browser from saving the input data.

    Example:-

    <form method="post">
       <input type="text" />
       <input type="password" autocomplete = "new-password"/>
       <input type="submit">
    </form>
    

    The first 2 solutions might not work since modern browsers provide a feature to save passwords i.e, they may ask to save the login credentials which will prevent the autocomplete = "off" to act.

    For Reference:-
    https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search