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

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

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

任何帮助都是感激的。


当前回答

Markus提出了一个很好的观点。我决定查找autocomplete属性,得到以下内容:

使用这个的唯一缺点 属性是不规范 (适用于IE和Mozilla浏览器), 并且会导致XHTML验证 失败。我认为这是一个 打破验证是合理的 然而。(源)

所以我不得不说,虽然它不是100%的工作,但在主要的浏览器处理,所以它是一个伟大的解决方案。

其他回答

真正的问题比在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.

您可以通过在每个显示中随机为密码字段使用的名称来防止浏览器匹配表单。然后浏览器看到与url相同的密码,但不能确定这是相同的密码。也许它在控制其他东西。

更新:注意,这应该是使用自动补全或其他策略的补充,而不是替代它们,因为其他人指出的原因。

还要注意,这只会阻止浏览器自动完成密码。它不会阻止它以浏览器选择使用的任意安全级别存储密码。

解决这个问题最简单的方法是将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>

autocomplete="off"不能在Firefox 31中禁用密码管理器,在一些早期版本中也很可能不能。

查看mozilla关于此问题的讨论: https://bugzilla.mozilla.org/show_bug.cgi?id=956906

我们希望使用第二个密码字段输入由令牌生成的一次性密码。现在我们使用文本输入而不是密码输入。:-(

如果autocomplete="off"不起作用…删除表单标签并使用div标签,然后使用jquery将表单值传递给服务器。这对我很管用。