MVC 5 - 防止密码存储

时间:2015-06-12 07:56:53

标签: asp.net-mvc html5

我需要阻止在我的MVC 5网站上存储用户名/密码。

我已将表单和输入元素都设置为autocomplete =“off”,我确信该网站正在运行HTML5。对于所有意图和目的,它不应该存储登录信息,但是,它仍然在登录后提示它。

正如所建议的那样,我尝试将输入字段名称更改为“username”和“password”以外的名称,但它没有改变任何内容。

我甚至尝试过添加虚拟用户名和放大器的技巧。密码隐藏在表单之外的元素,也在表单内部尝试过。没有快乐。

我也试过在jQuery中做,但没有成功

$("input").attr("autocomplete", "off");

表格标签:

<form action="/" autocomplete="off" class="form-horizontal" method="post" role="form" novalidate="novalidate">

输入元素:

<input autocomplete="off" class="form-control" data-val="true" data-val-regex="Mobile number must be a Numbers only." data-val-regex-pattern="[0-9]*\.?[0-9]+" data-val-required="The Mobile field is required." id="Username" name="Username" type="text" value="">

在IE和Chrome中测试过,但提示保存信息。

非常感谢任何帮助或建议。银行如何阻止这种情况?

1 个答案:

答案 0 :(得分:1)

我测试了许多解决方案,最后,提供了这个解决方案。

HTML代码

@Html.TextBoxFor(m => m.UserName, new { @class = "form-control", @placeholder = "UserName", @autofocus = "", @autocomplete = "off" })

@Html.TextBoxFor(m => m.Password, new { @class = "form-control", @placeholder = "Password", @autocomplete = "off" })

CSS代码

#Password {
    text-security: disc;
    -webkit-text-security: disc;
    -moz-text-security: disc;
}

JavaScript代码

window.onload = function () {
    init();
}

function init() {
    var x = document.getElementsByTagName("input")["Password"];
    var style = window.getComputedStyle(x);
    console.log(style);

    if (style.webkitTextSecurity) {
        // Do nothing
    } else {
        x.setAttribute("type", "password");
    }
}
相关问题