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

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

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

任何帮助都是感激的。


当前回答

我已经测试了在所有主要的浏览器中添加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();
 }
}

祝你好运! !

其他回答

另一种解决方案是使用隐藏表单使POST,其中所有输入的类型都是隐藏的。可见表单将使用“password”类型的输入。后一种表单永远不会被提交,所以浏览器根本无法拦截登录操作。

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

您的登录表单看起来像…

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

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

好吧,这是一个非常老的帖子,但我仍然会给出我的解决方案,这是我的团队长期以来一直在努力实现的。我们只是在表单中添加了一个新的input type="password"字段,并将其包装在div中,并使div隐藏起来。确保这个div在实际的密码输入之前。 这为我们工作,它没有提供任何保存密码选项

扑通- http://plnkr.co/edit/xmBR31NQMUgUhYHBiZSg?p=preview

HTML:

<form method="post" action="yoururl">
      <div class="hidden">
        <input type="password"/>
      </div>
      <input type="text" name="username" placeholder="username"/>
      <input type="password" name="password" placeholder="password"/>
    </form>

CSS:

.hidden {display:none;}

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>

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

jQuery示例:

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

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