简体   繁体   English

如何在IE11和FF30 +中禁用asp.net登录表单的保存密码

[英]How to disable save password for asp.net login forms in IE11 and FF30+

I want to disable the save password prompt in all browsers and hence I can avoid the auto fill for the password filed. 我想在所有浏览器中禁用“保存密码”提示,因此可以避免自动填写password

My code is working fine on Chrome But it wont work for me in IE11 and FireFox30+. 我的代码在Chrome上运行正常,但在IE11和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. 对此的任何想法都将受到高度赞赏。

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>

这是一个奇怪的解决方案,但是我在用户名之后使用了另一个密码字段,并将其隐藏起来对我有用。

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. 即使关闭了自动完成功能,最新的FF浏览器也会提示您输入保存密码。 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. 如果某些浏览器(例如IE8或更低版本)不支持该脚本,则可以通过在此脚本中打勾来单独排除该脚本。

<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. 因此,这里的想法是,使用类型为'password'的临时密码字段来从用户获取密码。 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). 然后,在用户提交密码之后,我们将使用脚本将密码从temp password字段复制到实际的密码字段(这是一个隐藏的文本字段)。 Then the temp field will be cleared and then we will change the type of that field from “password” to “text”. 然后将清除temp字段,然后将该字段的类型从“ password”更改为“ 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. 为了避免预先填充已经存储的密码,我们可以在表单中将第一个元素作为虚拟字段(无需为其提供名称或id属性),并使用密码类型将其隐藏。 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. 因此,实际的密码字段不会被预先填写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM