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

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

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

任何帮助都是感激的。


当前回答

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

其他回答

我的js (jquery)的解决方案是改变密码输入类型的文本在表单提交。密码可能在一秒钟内可见,所以我还隐藏了在此之前的输入。我宁愿不使用这个登录表单,但它是有用的(连同autocomplete="off"),例如在网站的管理部分。

在提交表单之前,试着把它放到一个控制台中(使用jquery)。

$('form').submit(function(event) {
    $(this).find('input[type=password]').css('visibility', 'hidden').attr('type', 'text');
});

在Chrome 44.0.2403.157(64位)上测试。

因为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。

Since most of the autocomplete suggestions, including the accepted answer, don't work in today's web browsers (i.e. web browser password managers ignore autocomplete), a more novel solution is to swap between password and text types and make the background color match the text color when the field is a plain text field, which continues to hide the password while being a real password field when the user (or a program like KeePass) is entering a password. Browsers don't ask to save passwords that are stored in plain text fields.

The advantage of this approach is that it allows for progressive enhancement and therefore doesn't require Javascript for a field to function as a normal password field (you could also start with a plain text field instead and apply the same approach but that's not really HIPAA PHI/PII-compliant). Nor does this approach depend on hidden forms/fields which might not necessarily be sent to the server (because they are hidden) and some of those tricks also don't work either in several modern browsers.

jQuery插件:

https://github.com/cubiclesoft/php-flexforms-modules/blob/master/password-manager/jquery.stoppasswordmanager.js

相关源代码来自上述链接:

(function($) {
$.fn.StopPasswordManager = function() {
    return this.each(function() {
        var $this = $(this);

        $this.addClass('no-print');
        $this.attr('data-background-color', $this.css('background-color'));
        $this.css('background-color', $this.css('color'));
        $this.attr('type', 'text');
        $this.attr('autocomplete', 'off');

        $this.focus(function() {
            $this.attr('type', 'password');
            $this.css('background-color', $this.attr('data-background-color'));
        });

        $this.blur(function() {
            $this.css('background-color', $this.css('color'));
            $this.attr('type', 'text');
            $this[0].selectionStart = $this[0].selectionEnd;
        });

        $this.on('keydown', function(e) {
            if (e.keyCode == 13)
            {
                $this.css('background-color', $this.css('color'));
                $this.attr('type', 'text');
                $this[0].selectionStart = $this[0].selectionEnd;
            }
        });
    });
}
}(jQuery));

演示:

https://barebonescms.com/demos/admin_pack/admin.php

点击菜单中的“添加条目”,然后滚动到页面底部的“模块:停止密码管理器”。

免责声明:虽然这种方法适用于视力正常的人,但屏幕阅读器软件可能存在问题。例如,屏幕阅读器可能会大声读出用户的密码,因为它看到的是纯文本字段。使用上述插件还可能产生其他不可预见的后果。改变内置的web浏览器功能应该通过测试各种各样的条件和边缘情况来进行。

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

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

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

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