在政府医疗机构工作的乐趣之一是必须处理所有围绕PHI(受保护的健康信息)的偏执。不要误解我的意思,我支持尽一切可能保护人们的个人信息(健康状况、财务状况、上网习惯等),但有时人们会有点太神经质了。

举个例子:我们的一位州客户最近发现浏览器提供了保存密码的方便功能。我们都知道它已经存在了一段时间,完全是可选的,由最终用户决定是否使用它是一个明智的决定。然而,目前有一点骚动,我们被要求找到一种方法来禁用我们网站的功能。

问:网站有没有办法告诉浏览器不要提供记住密码的功能?我从事网络开发已经很长时间了,但我不知道我以前遇到过这种情况。

任何帮助都是感激的。


当前回答

最干净的方法是使用autocomplete="off"标签属性but 当你用Tab切换字段时,Firefox不能正确地遵守它。

唯一可以阻止这种情况的方法是添加一个虚假的隐藏密码字段,它会欺骗浏览器在那里填充密码。

<input type="text" id="username" name="username"/>
<input type="password" id="prevent_autofill" autocomplete="off" style="display:none" tabindex="-1" />
<input type="password" id="password" autocomplete="off" name="password"/>

这是一种丑陋的黑客行为,因为你改变了浏览器的行为,这应该被认为是糟糕的做法。只有在你真的需要的时候才使用它。

注意:这将有效地停止密码自动填充,因为FF将“保存”#prevent_autofill的值(它是空的),并将尝试填充那里保存的任何密码,因为它总是使用在DOM中分别输入“username”之后找到的第一个type=“password”输入。

其他回答

我认为加上autocomplete="off"一点用都没有

我有另一个解,

<input type="text" name="preventAutoPass" id="preventAutoPass" style="display:none" />

在输入密码之前添加此选项。

例如:<input type=“text” name=“txtUserName” id=“txtUserName” /> <输入类型=“文本” 名称=“防止自动传递” id=“防止自动传递” 样式=“显示:无” /> <输入类型=“密码” 名称=“txtPass” id=“txtPass” autocomplete=“off” />

这并不会阻止浏览器询问并保存密码。但它阻止了密码的填写。

欢呼

恕我直言, 最好的方法是随机选择type=password的输入字段的名称。 使用“pwd”前缀,然后是一个随机数。 动态创建字段并将表单呈现给用户。

您的登录表单看起来像…

<form>
   <input type=password id=pwd67584 ...>
   <input type=text id=username ...>
   <input type=submit>
</form>

然后,在服务器端,当您分析客户端发布的表单时,捕获以“pwd”开头的字段,并将其用作“password”。

我已经测试了在所有主要的浏览器中添加autocomplete="off"的表单标签。事实上,到目前为止,美国大多数人都在使用IE8。

IE8, IE9, IE10, Firefox, Safari都可以。 浏览器没有提示“保存密码”。 另外,以前保存的用户名和密码没有填充。 Chrome & ie11不支持自动完成="off"功能 FF支持autocomplete="off"。但有时已经存了 填充凭证。

2014年6月11日更新

最后,下面是一个使用javascript的跨浏览器解决方案,它可以在所有浏览器中正常工作。

需要删除登录表单中的“表单”标签。在客户端验证之后,将凭据放入隐藏表单并提交。

另外,添加两个方法。一个用于验证“validateLogin()”,另一个用于在文本框/密码/按钮“checkAndSubmit()”中单击回车时监听进入事件。因为现在登录表单没有表单标签,所以输入事件在这里不起作用。

HTML

<form id="HiddenLoginForm" action="" method="post">
<input type="hidden" name="username" id="hidden_username" />
<input type="hidden" name="password" id="hidden_password" />
</form>

Username: <input type="text" name="username" id="username" onKeyPress="return checkAndSubmit(event);" /> 
Password: <input type="text" name="password" id="password" onKeyPress="return checkAndSubmit(event);" /> 
<input type="button" value="submit" onClick="return validateAndLogin();" onKeyPress="return checkAndSubmit(event);" /> 

Javascript

//For validation- you can modify as you like
function validateAndLogin(){
  var username = document.getElementById("username");
  var password = document.getElementById("password");

  if(username  && username.value == ''){
    alert("Please enter username!");
    return false;
  }

  if(password && password.value == ''){
    alert("Please enter password!");
    return false;
  }

  document.getElementById("hidden_username").value = username.value;
  document.getElementById("hidden_password").value = password.value;
  document.getElementById("HiddenLoginForm").submit();
}

//For enter event
function checkAndSubmit(e) {
 if (e.keyCode == 13) {
   validateAndLogin();
 }
}

祝你好运! !

解决这个问题最简单的方法是将INPUT字段放在FORM标记之外,并在FORM标记内部添加两个隐藏字段。然后在提交事件侦听器中,在表单数据提交到服务器之前,将值从可见输入复制到不可见输入。

下面是一个例子(你不能在这里运行它,因为表单动作没有设置为一个真正的登录脚本):

<!doctype html> <html> <head> <title>Login & Save password test</title> <meta charset="utf-8"> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> </head> <body> <!-- the following fields will show on page, but are not part of the form --> <input class="username" type="text" placeholder="Username" /> <input class="password" type="password" placeholder="Password" /> <form id="loginForm" action="login.aspx" method="post"> <!-- thw following two fields are part of the form, but are not visible --> <input name="username" id="username" type="hidden" /> <input name="password" id="password" type="hidden" /> <!-- standard submit button --> <button type="submit">Login</button> </form> <script> // attache a event listener which will get called just before the form data is sent to server $('form').submit(function(ev) { console.log('xxx'); // read the value from the visible INPUT and save it to invisible one // ... so that it gets sent to the server $('#username').val($('.username').val()); $('#password').val($('.password').val()); }); </script> </body> </html>

<input type="text" id="mPassword" required="required" title="Valid password required" autocomplete="off" list="autocompleteOff" readonly onfocus="this.removeAttribute('readonly');" style="text-security:disc; -webkit-text-security:disc;" oncopy="return false;" onpaste="return false;"/>