在Firefox 30.0 / Chrome版本35.0.1916.153 m中禁用浏览器中的密码

时间:2014-07-01 09:59:41

标签: javascript jquery asp.net

我正在使用重定向到下一页的登录页面,但在重定向时我会记住浏览器端的密码。如何禁用它

以下代码适用于IE-8

但不适用于Mozilla Firefox 30.0

和Chrome 35

<body>
<form id="form1" runat="server" method="post" autocomplete="off">
<div>
<table>
<tr>
<td>UserName</td>
<td><asp:TextBox ID="txtName" runat="server"/></td>
</tr>
<tr>
<td>Password</td>
<td><asp:TextBox ID="txtPwd" runat="server" TextMode="Password" autocomplete="off" /></td>
</tr>
 <tr>
 <td></td>
<td><asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" /></td>
</tr>
</table>
</div>
</form>
</body>

protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
    if (txtName.Text == "user" && txtPwd.Text == "pass")
    {
        txtPwd.Attributes.Add("autocomplete", "off");

        Response.Redirect("Register.aspx");
    }
    else
    {
    }
}

2 个答案:

答案 0 :(得分:0)

这是一项浏览器特定功能,并且由于兼容性问题,主要浏览器已停止支持。 Is autocomplete="off" compatible with all modern browsers?

答案 1 :(得分:-1)

使用:

<input onclick="request ();" type="button" value="Submit form" />

而不是任何提交输入和名为的函数:“request”为您的php文件调用“XMLHttpRequest”。
示例小提琴:JSFiddle

注意:小提琴输出:“错误:未找到”,因为在同一个目录中没有:“parse.php”。在您的脚本中,您需要更改“数据”对象中的名称和参数。

更新

<?php
    function decodeURIComponent ( $string ) { return rawurldecode ( $string ); }
    function encodeURIComponent ( $string ) { return ( decodeURIComponent ( $string ) === $string ? rawurlencode ( $string ) : $string ); }
    function isLogged ( $email, $password ) { return ( ( $email === encodeURIComponent ( "nobody@example.com" ) && $password === encodeURIComponent ( "reallyStrongPassword" ) ) ? true : false ); }
    foreach ( $_POST as $key => $value ) { $params [ encodeURIComponent ( $key ) ] = encodeURIComponent ( $value ); }
    // added encode checking and change API to JavaScript like
    // better security ( if JavaScript was modified )
    $count = count ( $_POST );
    if ( $count === 2 && isset ( $params [ "email" ] ) && isset ( $params [ "password" ] ) ) // security checks
    {
        $email = $params [ "email" ];
        $password = $params [ "password" ];
        /* here I check $email and $password with their hashes in MySQL file */
        $good = isLogged ( $email, $password );
        if ( $good ) { echo "<h1>Sucessfull logged in !</h1>"; }
        else { echo "<h1>Bad e-mail or password or not already registered !"; }
    }
    else { exit ( "Security critical error !" ); }
?>

注意:这只是一个示例代码...
注意:在安全案例中,encodeURIComponent非常重要。

更新了小提琴:JSFiddle