禁用某些密码输入字段的Firefox密码管理器

时间:2011-11-17 07:24:16

标签: html firefox passwords

我有一份注册表和一份登录表。登录表单(我的)Firefox默认提供用户名和密码,这没关系。但是在注册表上它也是一样的 - 这没有任何意义,它会产生问题,因为输入密码字段而“重复密码”字段不是。

我是否可以更改注册表单的HTML,以便Firefox和其他浏览器无法自动填写特定密码字段

编辑:我发现了很多关于此主题的问题(和答案),但建议的解决方案(在密码输入字段设置autocomplete=off不起作用对我来说,Firefox(它仍然自动填充该字段)。我找到this solution,但它看起来有点难看(如果用户输入用户名并点击Tab,则不起作用)。有谁知道更好的方法?

3 个答案:

答案 0 :(得分:9)

找到一个simple and elegant solution,它也应该是跨浏览器的。无法相信我没想到 - 您只需在自己之前添加另一个密码输入然后隐藏它:

<input style="display:none" type="password" name="foilautofill"/>
<input type="password" name="notautofilledpassword" />

美丽。 :)

答案 1 :(得分:2)

如果我们有许多用户与敏感信息共享同一台计算机,我们需要在密码上禁用自动填充功能。起初我尝试了“简单而优雅”的隐藏密码解决方案,但是一位聪明的用户告诉我,任何人都可以使用浏览器的开发人员工具在隐藏文本中以纯文本显示自动填充的密码领域。

我以安全的方式禁用了密码自动完成功能,如下所示。这适用于Firefox 29和IE8:


动态创建密码字段,并在页面加载时将其附加到表单。给它一个占位符属性。

function createPasswordInput() {
var dynpass = document.createElement("input");
dynpass.setAttribute("type", "password");
dynpass.setAttribute("size", 32);
dynpass.setAttribute("id",   "dynPwElem");

    // placeholder helps prevent password autocomplete
dynpass.setAttribute("placeholder", "Enter password");

// append the password element to the form, in my case an empty table cell
var td = document.getElementById("dynamicTd");
td.appendChild(dynpass);

var rpw = document.getElementById("dynPwElem");
rpw.setAttribute("name", "userPassword");

// Max length starts at only 1, helps prevent autocomplete. 
// Use property maxLength instead of setAttribute to work in IE
rpw.maxLength = "1"; // set the DOM property that has uppercase L

将密码元素maxLength属性设置为1,并附加onfocus事件以将maxLength扩展为它应该是什么(在我的情况下为32)。

function expandPwLength() {
var rpw = document.getElementById("dynPwElem");
// use property maxLength instead of setAttribute to work in IE
if (rpw.maxLength < 32) {
    rpw.maxLength = 32;
}
} 

// attach focus event to expand the password field length
if (rpw.addEventListener) {
    rpw.addEventListener("focus", expandPwLength, true);
} else {
    rpw.attachEvent("onfocus", expandPwLength); // IE <= 8
}

如果用户使用击键事件监听器点击用户ID字段中的“Enter”,则阻止表单提交。而是将插入符号移动到密码字段。

function preventAutocomplete (charCode) {
if (charCode == 13) {
    // instead of autocompleting password, navigate to the password field.
        document.getElementById("dynPwElem").focus();
    }
    }
}

在同一个击键事件侦听器中,截断密码元素的自动完成属性。

if (charCode == 13 || charCode == 40) // the Enter key, or the Down-arrow key
    document.forms["loginSubmitForm"].userPassword.autocomplete = "";

在页面加载时使用JavaScript将整个表单属性“autocomplete”设置为“off”,而不是在HTML标记中。

document.forms["loginSubmitForm"].autocomplete="off";

答案 2 :(得分:1)

在得到这个问题之前,我解决了问题,几乎和JohnDodo提到的一样优雅,并且像MissHilton一样安全。在密码输入字段之前引入一个不可见的虚拟用户输入字段,并使用不存在的用户名填充JS / JQuery代码。 Firefox将查找该用户的密码,以显示其密码,但当然这将失败。我在改变密码页面使用了它,并将Firefox的行为视为一个错误。浏览器应该只在存储它的URL上填写存储的密码,而不是在其他页面上填写。

这是我的jQuery / html代码:

<script language="javascript" type="text/javascript">
    $("#dummyusername").ready(function () {
        $("#dummyusername").val("joe_x_dummy");
    });
</script>

<input style="display:none" type="text" name="dummyusername" id="dummyusername" />
<input type="password" name="oldpassword" ...