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

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

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

任何帮助都是感激的。


当前回答

我周围有个工作,可能会有帮助。

你可以自定义字体。所以,做一个自定义字体,所有的字符为点/圆/星号为例。使用它作为你网站的自定义字体。检查如何做到这一点在inkscape:如何使自己的字体

然后在你的登录表单上使用:

<form autocomplete='off'  ...>
   <input type="text" name="email" ...>
   <input type="text" name="password" class="password" autocomplete='off' ...>
   <input type=submit>
</form>

然后添加css:

@font-face {
    font-family: 'myCustomfont';
    src: url('myCustomfont.eot');
    src: url('myCustomfont?#iefix') format('embedded-opentype'),
         url('myCustomfont.woff') format('woff'),
         url('myCustomfont.ttf') format('truetype'),
         url('myCustomfont.svg#myCustomfont') format('svg');
    font-weight: normal;
    font-style: normal;

}
.password {
  font-family:'myCustomfont';
}

很好的跨浏览器兼容性。我尝试过IE6+、FF、Safari和Chrome浏览器。只要确保你转换的oet字体不会被损坏。希望有帮助?

其他回答

由于Internet Explorer 11不再支持input type="password"字段的autocomplete="off"(希望其他浏览器不会效仿他们的做法),最简洁的方法(在撰写本文时)似乎是让用户在不同的页面提交他们的用户名和密码,即用户输入他们的用户名,提交,然后输入密码并提交。美国银行和汇丰银行的网站也在使用这种方法。

因为浏览器无法将密码与用户名关联起来,所以它不会提供存储密码的功能。这种方法适用于所有主流浏览器(在撰写本文时),无需使用Javascript也能正常运行。缺点是,它将更麻烦的用户,将采取2回传为一个登录操作,而不是一个,所以这真的取决于你的网站需要多安全。

更新:正如Gregory在这篇评论中提到的,Firefox将效仿IE11,忽略密码字段的autocomplete="off"。

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

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

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

If you do not want to trust the autocomplete flag, you can make sure that the user types in the box using the onchange event. The code below is a simple HTML form. The hidden form element password_edited starts out set to 0. When the value of password is changed, the JavaScript at the top (pw_edited function) changes the value to 1. When the button is pressed, it checks the valueenter code here before submitting the form. That way, even if the browser ignores you and autocompletes the field, the user cannot pass the login page without typing in the password field. Also, make sure to blank the password field when focus is set. Otherwise, you can add a character at the end, then go back and remove it to trick the system. I recommend adding the autocomplete="off" to password in addition, but this example shows how the backup code works.

<html>
  <head>
    <script>
      function pw_edited() {
        document.this_form.password_edited.value = 1;
      }
      function pw_blank() {
        document.this_form.password.value = "";
      }
      function submitf() {
        if(document.this_form.password_edited.value < 1) {
          alert("Please Enter Your Password!");
        }
        else {
         document.this_form.submit();
        }
      }
    </script>
  </head>
  <body>
    <form name="this_form" method="post" action="../../cgi-bin/yourscript.cgi?login">
      <div style="padding-left:25px;">
        <p>
          <label>User:</label>
          <input name="user_name" type="text" class="input" value="" size="30" maxlength="60">
        </p>
        <p>
          <label>Password:</label>
          <input name="password" type="password" class="input" size="20" value="" maxlength="50" onfocus="pw_blank();" onchange="pw_edited();">
        </p>
        <p>
          <span id="error_msg"></span>
        </p>
        <p>
          <input type="hidden" name="password_edited" value="0">
          <input name="submitform" type="button" class="button" value="Login" onclick="return submitf();">
        </p>
      </div>
    </form>
  </body>
</html>

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

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

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

我知道的一种方法是在提交表单之前使用(例如)JavaScript从密码字段中复制值。

这样做的主要问题是解决方案与JavaScript绑定在一起。

同样,如果它可以绑定到JavaScript,那么在向服务器发送请求之前,不妨在客户端对密码进行哈希处理。