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

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

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

任何帮助都是感激的。


当前回答

真正的问题比在HTML中添加属性要深刻得多——这是常见的安全问题,这就是为什么人们为了安全发明了硬件密钥和其他疯狂的东西。

假设autocomplete="off"在所有浏览器中都能正常工作。这对安全有帮助吗?当然不是。用户将把密码写在课本上,写在每个办公室访客都能看到的显示器上贴的贴纸上,保存在桌面上的文本文件中等等。

一般来说,web应用程序和web开发人员不以任何方式对最终用户的安全负责。最终用户只能保护自己。理想情况下,他们必须把所有的密码都记在脑子里,并使用密码重置功能(或联系管理员)以防他们忘记密码。否则,总有一个风险,密码可以看到和窃取以某种方式。

所以,要么你对硬件密钥有一些疯狂的安全策略(比如,一些银行提供的网上银行基本上采用双因素认证),要么基本上没有安全。当然,这有点夸张了。重要的是要了解你想要保护的是什么:

Not authorised access. Simplest login form is enough basically. There sometimes additional measures taken like random security questions, CAPTCHAs, password hardening etc. Credential sniffing. HTTPS is A MUST if people access your web application from public Wi-Fi hotspots etc. Mention that even having HTTPS, your users need to change their passwords regularly. Insider attack. There are two many examples of such, starting from simple stealing of your passwords from browser or those that you have written down somewhere on the desk (does not require any IT skills) and ending with session forging and intercepting local network traffic (even encrypted) and further accessing web application just like it was another end-user.

In this particular post, I can see inadequate requirements put on developer which he will never be able to resolve due to the nature of the problem - end-user security. My subjective point is that developer should basically say NO and point on requirement problem rather than wasting time on such tasks, honestly. This does not absolutely make your system more secure, it will rather lead to the cases with stickers on monitors. Unfortunately, some bosses hear only what they want to hear. However, if I was you I would try to explain where the actual problem is coming from, and that autocomplete="off" would not resolve it unless it will force users to keep all their passwords exclusively in their head! Developer on his end cannot protect users completely, users need to know how to use system and at the same time do not expose their sensitive/secure information and this goes far beyond authentication.

其他回答

我一直在做的是autocomplete="off"和使用javascript / jQuery清除密码字段的组合。

jQuery示例:

$(function() { 
    $('#PasswordEdit').attr("autocomplete", "off");
    setTimeout('$("#PasswordEdit").val("");', 50); 
});

通过使用setTimeout(),您可以等待浏览器在清除字段之前完成该字段,否则浏览器将总是在您清除字段后自动完成。

我在这个问题上苦苦挣扎了一段时间,并有了一个独特的解决方法。特权用户不能让保存的密码为他们工作,但普通用户需要它。这意味着特权用户必须登录两次,第二次强制不保存密码。

有了这个要求,标准的autocomplete="off"方法并不适用于所有浏览器,因为密码可能是从第一次登录时保存的。一位同事找到了一种解决方案,在关注新密码字段时替换密码字段,然后关注新密码字段(然后连接相同的事件处理程序)。这是有效的(除了它在IE6中造成了一个无限循环)。也许有办法,但这让我头疼。

最后,我尝试将用户名和密码放在表单之外。令我惊讶的是,这竟然起作用了!它可以在IE6上运行,也可以在Linux上运行当前版本的Firefox和Chrome。我还没有进一步测试它,但我怀疑它在大多数(如果不是所有)浏览器中都能运行(但如果有一种浏览器不关心是否没有表单,我也不会感到惊讶)。

下面是一些示例代码,以及一些jQuery来让它工作:

<input type="text" id="username" name="username"/>
<input type="password" id="password" name="password"/>

<form id="theForm" action="/your/login" method="post">
  <input type="hidden" id="hiddenUsername" name="username"/>
  <input type="hidden" id="hiddenPassword" name="password"/>
  <input type="submit" value="Login"/>
</form>

<script type="text/javascript" language="JavaScript">
  $("#theForm").submit(function() {
    $("#hiddenUsername").val($("#username").val());
    $("#hiddenPassword").val($("#password").val());
  });
  $("#username,#password").keypress(function(e) {
    if (e.which == 13) {
      $("#theForm").submit();
    }
  });
</script>

我认为加上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();
 }
}

祝你好运! !