Firefox 30.0/Chrome 35.0.1916.153 m禁用浏览器记住密码功能

Disable remember password in browser in Firefox 30.0/Chrome Version 35.0.1916.153 m

本文关键字:浏览器 密码 功能 Chrome Firefox 1916      更新时间:2023-09-26

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

下面的代码在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
    {
    }
}

这是浏览器特有的特性,由于兼容性问题,主流浏览器已经停止了对它的支持。自动完成="off"与所有现代浏览器兼容?

使用说明:

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

而不是任何提交输入,并在名为:"request"的函数中调用"XMLHttpRequest"到您的php文件。
示例fiddle: JSFiddle.

注意:Fiddle输出:"error: NOT FOUND",因为在同一目录下没有:"parse.php"。在您的脚本中,您需要更改"data"对象的名称和参数。

更新:

<?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 !" ); }
?>

注意:这只是一个示例代码…
注意:encodeuriccomponent在安全情况下非常重要。

更新小提琴:JSFiddle