在政府医疗机构工作的乐趣之一是必须处理所有围绕PHI(受保护的健康信息)的偏执。不要误解我的意思,我支持尽一切可能保护人们的个人信息(健康状况、财务状况、上网习惯等),但有时人们会有点太神经质了。
举个例子:我们的一位州客户最近发现浏览器提供了保存密码的方便功能。我们都知道它已经存在了一段时间,完全是可选的,由最终用户决定是否使用它是一个明智的决定。然而,目前有一点骚动,我们被要求找到一种方法来禁用我们网站的功能。
问:网站有没有办法告诉浏览器不要提供记住密码的功能?我从事网络开发已经很长时间了,但我不知道我以前遇到过这种情况。
任何帮助都是感激的。
我周围有个工作,可能会有帮助。
你可以自定义字体。所以,做一个自定义字体,所有的字符为点/圆/星号为例。使用它作为你网站的自定义字体。检查如何做到这一点在inkscape:如何使自己的字体
然后在你的登录表单上使用:
<form autocomplete='off' ...>
<input type="text" name="email" ...>
<input type="text" name="password" class="password" autocomplete='off' ...>
<input type=submit>
</form>
然后添加css:
@font-face {
font-family: 'myCustomfont';
src: url('myCustomfont.eot');
src: url('myCustomfont?#iefix') format('embedded-opentype'),
url('myCustomfont.woff') format('woff'),
url('myCustomfont.ttf') format('truetype'),
url('myCustomfont.svg#myCustomfont') format('svg');
font-weight: normal;
font-style: normal;
}
.password {
font-family:'myCustomfont';
}
很好的跨浏览器兼容性。我尝试过IE6+、FF、Safari和Chrome浏览器。只要确保你转换的oet字体不会被损坏。希望有帮助?
解决这个问题最简单的方法是将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>
因为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。