由于大多数自动完成建议(包括被接受的答案)在当今的Web浏览器中不起作用(即Web浏览器密码管理器忽略自动完成),因此更为新颖的解决方案是在纯文本字段和密码字段之间切换密码和文本类型,并在字段为纯文本字段时使背景颜色匹配文本颜色,这样可以继续隐藏密码,同时在用户(或像KeePass这样的程序)输入密码时成为真正的密码字段。浏览器不会要求保存存储在纯文本字段中的密码。
这种方法的优点是它允许渐进式增强,因此不需要Javascript才能使字段像正常的密码字段一样工作(您也可以从纯文本字段开始,然后应用相同的方法,但那并不是真正符合HIPAA PHI / PII标准)。此外,这种方法也不依赖于可能不会发送到服务器的隐藏表单/字段(因为它们是隐藏的),其中一些技巧在一些现代浏览器中也不起作用。
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
在菜单中点击“添加条目”,然后滚动到页面底部找到“模块:停止密码管理器”。
免责声明:虽然这种方法适用于视觉障碍者,但屏幕阅读器软件可能会出现问题。例如,屏幕阅读器可能会大声读出用户的密码,因为它看到了一个明文字段。使用上述插件还可能存在其他不可预见的后果。更改内置网页浏览器功能应该谨慎进行,并测试各种条件和边缘情况。