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

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

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

任何帮助都是感激的。


当前回答

因为autocomplete="off"对密码字段不起作用,所以必须依赖javascript。这里有一个简单的解决方案,基于这里找到的答案。

添加属性data-password-autocomplete="off"到你的密码字段:

<input type="password" data-password-autocomplete="off">

包括以下JS:

$(function(){
    $('[data-password-autocomplete="off"]').each(function() {
        $(this).prop('type', 'text');
        $('<input type="password"/>').hide().insertBefore(this);
        $(this).focus(function() {
            $(this).prop('type', 'password');
        });
    });     
});

这个解决方案适用于Chrome和FF。

其他回答

autocomplete="off"适用于大多数现代浏览器,但我使用的另一种方法是在Epiphany(一种支持webkit的GNOME浏览器)中成功工作,即在会话状态中存储一个随机生成的前缀(或一个隐藏字段,我碰巧在会话状态中已经有一个合适的变量),并使用它来更改字段的名称。Epiphany仍然想要保存密码,但当返回到表单时,它不会填充字段。

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

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

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

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

好吧,这是一个非常老的帖子,但我仍然会给出我的解决方案,这是我的团队长期以来一直在努力实现的。我们只是在表单中添加了一个新的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;}

面对同样的HIPAA问题,我找到了一个相对简单的解决方案,

创建一个隐藏密码字段,字段名为数组。 <input type="password" name="password[]" style="display:none" /> 实际密码字段使用相同的数组。 /> . <input type="password" name="password[]

浏览器(Chrome)可能会提示你“保存密码”,但无论用户是否选择保存,下次登录时,密码将自动填充隐藏的密码字段,数组中的零槽,使第一个槽为空。

我尝试定义数组,例如“password[part2]”,但它仍然记得。我认为如果它是一个无索引数组,它就会丢弃它因为它别无选择,只能把它放在第一个位置。

然后使用你选择的编程语言访问数组,比如PHP,

echo $_POST['password'][1];