在政府医疗机构工作的乐趣之一是必须处理所有围绕PHI(受保护的健康信息)的偏执。不要误解我的意思,我支持尽一切可能保护人们的个人信息(健康状况、财务状况、上网习惯等),但有时人们会有点太神经质了。
举个例子:我们的一位州客户最近发现浏览器提供了保存密码的方便功能。我们都知道它已经存在了一段时间,完全是可选的,由最终用户决定是否使用它是一个明智的决定。然而,目前有一点骚动,我们被要求找到一种方法来禁用我们网站的功能。
问:网站有没有办法告诉浏览器不要提供记住密码的功能?我从事网络开发已经很长时间了,但我不知道我以前遇到过这种情况。
任何帮助都是感激的。
我不确定它是否能在所有浏览器中工作,但你应该尝试在表单上设置autocomplete="off"。
<form id="loginForm" action="login.cgi" method="post" autocomplete="off">
禁用表单和密码存储提示并防止表单数据在会话历史中缓存的最简单和最简单的方法是使用值为“off”的自动完成表单元素属性。
从https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
一些小研究表明,这可以在IE中工作,但我不能保证;)
@Joseph:如果严格要求通过实际标记的XHTML验证(不知道为什么会这样),理论上你可以在之后用javascript添加这个属性,但禁用js的用户(可能可以忽略不计,如果你的网站需要js,则为零)仍然会保存他们的密码。
jQuery示例:
$('#loginForm').attr('autocomplete', 'off');
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>
我的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位)上测试。