2

I want to disable the save password prompt in all browsers and hence I can avoid the auto fill for the password filed.

My code is working fine on Chrome But it wont work for me in IE11 and FireFox30+.

Here is my code:

   <form id="form1" runat="server" autocomplete="off">         
        <div id="Login-body" class="clearfix">
            <ul>
                <li><span>UserName: </span>
                    <asp:TextBox ID="TextBox1" runat="server" autocomplete="off" />
                </li>
                <li><span>Password: </span>
                    <asp:TextBox ID="TextBox2" runat="server"  
                     TextMode="Password" autocomplete="off" />
                </li>
            </ul>
        </div>
          <asp:Button ID="Button1" runat="server" Text="Login" />
    </div>
</form>

Any thoughts on the same are highly appreciated.

  • possible duplicate of [Disable browser 'Save Password' functionality](http://stackoverflow.com/questions/32369/disable-browser-save-password-functionality) – Izzy Jan 28 '15 at 09:13
  • I have looked in to your answer looks good for me (Cheers) @MuratYıldız – Arun Chandran Chackachattil May 25 '16 at 09:57
  • @ArunChandranC I am happy that it was helpful for you. So, could you please vote up the answer on that page so that the other people can also benefit from it? Thanks. – Murat Yıldız May 25 '16 at 20:04

3 Answers3

2

I added a new password type input element

 <input style="display: none" type="password" id="TextBox1">

This worked the trick for me.

The following is the my working code

<form id="form1" runat="server" autocomplete="off">         
    <div id="Login-body" class="clearfix">
        <ul>
            <li><span>UserName: </span>
                <asp:TextBox ID="TextBox1" runat="server" autocomplete="off" />
            </li>
            <li><span>Password: </span>
            <input style="display: none" type="password" id="TextBox1">
                <asp:TextBox ID="TextBox2" runat="server"  
                 TextMode="Password" autocomplete="off" />
            </li>
        </ul>
    </div>
      <asp:Button ID="Button1" runat="server" Text="Login" />
</div>

1

It's a strange solution but I had used another password field just after the user name and hide it and it worked for me.

शेखर
  • 17,412
  • 13
  • 61
  • 117
0

In addition to the above, there is a trick to avoid save password prompt by dynamically changing the field type. Latest FF browsers prompting for save password even though the autocomplete is turned off. For that the below trick will help. If it is not supported in some browsers like IE8 or below versions then we can exclude this script for those browsers alone by putting a check in this script.

<html>
  <head>
    <script>
      function submitIt(obj){
        document.getElementById("actualPassword").value=document.getElementById("tempPasswd").value;                                     
        document.getElementById("tempPasswd").value="";
        document.getElementById("tempPasswd").type="text";                    /* To avoid browser save-password prompt */
        document.getElementById("loginform").submit();
        return true;
      }
    </script>
  </head>
  <body>
    <form name="loginform" id="loginform" method="POST" autocomplete="off">
     <div style="display:none">  <input id=”dummy” type="password" value="" autocomplete="off" /> </div>                                    /*To stop prefilling value for the actual password field*/
      <input name="username" id="username" type="text" value="testUser " autocomplete="off" />
      <input name="tempPasswd" id="tempPasswd" type="password" value="" autocomplete="off" />
      <input name="actualPassword" id="actualPassword" type="text" value="" autocomplete="off" />
      <input name="submit12" id="submit12" type="button" value="submit" onclick="submitIt()" />
    </form>
   </body>
</html>

How it works:

  1. Browsers prompting for save password if they see a password type field after we submit the form. So the idea here is, to use a temp password field with type ‘password’ to get the password from the user. Then after user submits it, we will use the script to copy the password from temp password field to the actual password field (which is a hidden text field). Then the temp field will be cleared and then we will change the type of that field from “password” to “text”. So that browser won’t find any password fields in the form while it gets submitted and it won’t prompt for save password.

  2. To avoid pre-filling the passwords which are stored already we can have a dummy field (no need to provide a name or id attributes to it) with password type in our form as a first element and then can hide it using style. So that browser will tend to prefill that dummy hidden password field and it won’t appear on the screen. The actual password field wont get pre-filled due to this.

Kannan R
  • 11
  • 1