2017-02-17 51 views
0

我试图制作一个登录表单,它向服务器提交加密密码,同时在表单外的隐藏字段上设置明文。Internet Explorer将错误的输入保存为密码

在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> 
+0

请点击''''代码片段编辑器按钮,而不是粘贴ASP,只将HTML和JS粘贴到[mcve] – mplungjan

+0

对不起,但片段编辑器似乎无法识别ASP,因为它需要理解我的问题。 – Lucas

+0

你的问题看起来像是/ HTML/JavaScript,只有 – mplungjan

回答

0

您在txtPassword存储加密的密码发布到服务器,这就是为什么I.E收藏起来之前。您可以在隐藏字段中存储加密密码,并在身份验证期间从此处检索密码。

替换该行

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

东西

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

其中hfPassword将隐藏字段,你必须把它添加到窗体。

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

+0

,但密码也会以纯文本形式提交给服务器,我不打算购买https证书。 – Lucas

+0

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

+0

但如果表单提交时txtPassword位于表单内,它也会被提交。但是我已经在提交一个解决方案,其中包括设置'disabled ='disabled'',如果有任何错误,请将其解除设置 – Lucas