【问题标题】:Internet Explorer saving the wrong input as passwordInternet Explorer 将错误的输入保存为密码
【发布时间】:2017-07-06 22:51:04
【问题描述】:

我正在尝试制作一个向服务器提交加密密码的登录表单,同时将明文设置在表单外的隐藏字段中。

在 Chrome/Firefox 中,它会记住隐藏字段中设置的登录名/密码,而在 IE 中,它会记住加密的密码。

我想知道如何解决这个问题。

这是我所拥有的:

<script>
    function encryptPassword() {
        var txtUsername= document.getElementById("txtUsername");
        var txtPassword= document.getElementById("txtPassword");

        document.getElementById('username').value = txtUsername.value;
        document.getElementById('password').value = txtPassword.value;

        txtPassword.value = encrypt(md5(txtPassword.value), "<%=pubKey %>");
    }
</script>

<div style="visibility: hidden">
    <input type="text" name="username" id="username" style="width:0;height:0" tabindex="-1" />
    <input type="password" name="password" id="password" style="width:0;height:0" tabindex="-1" />
</div>

<form id="form1" runat="server">
    <asp:TextBox ID="txtUsername" autofocus="autofocus" required="required"  runat="server" />
    <asp:TextBox ID="txtPassword" TextMode="Password" required="required" runat="server" />
    <asp:Button ID="btnLogin" OnClick="btnOk_Click" OnClientClick="encryptPassword();" runat="server" />
</form>

【问题讨论】:

  • 请点击&lt;&gt;sn-p 编辑器按钮,而不是粘贴ASP,只粘贴HTML和JS到minimal reproducible example
  • 抱歉,sn-p 编辑器似乎无法识别 ASP,因为它是理解我的问题所必需的。
  • 您的问题看起来只是表单/HTML/JavaScript

标签: asp.net internet-explorer passwords forms


【解决方案1】:

您在将加密密码发布到服务器之前将其存储在txtPassword 中,这就是I.E 存储它的原因。您可以将加密密码存储在隐藏字段中,并在身份验证期间从那里检索。

替换这一行

txtPassword.value = encrypt(md5(txtPassword.value), "<%=pubKey %>");

某事

hfPassword.value = encrypt(md5(txtPassword.value), "<%=pubKey %>");

hfPassword 将是隐藏字段,您必须将其添加到表单中。

我将被保存为加密文本。不要保存 txtPassword 值。改为保存 hfPassword。 txtPassword 将仅用于用户交互和加密功能的输入。

【讨论】:

  • 但是密码也会以明文形式提交给服务器,我不打算购买 https 证书。
  • 没有。我将被保存为加密文本。不要保存 txtPassword 值。改为保存 hfPassword。 txtPassword 将仅用于用户交互和加密功能的输入。
  • 但是如果表单提交时txtPassword在表单内部,也会被提交。但我已经在研究一个解决方案,涉及在提交之前设置disabled='disabled',如果有任何错误则取消设置
猜你喜欢
  • 2011-03-02
  • 2012-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多