1

我必须用我的 PHP 登录脚本修复一些错误,当用户使用大写字母创建帐户时,它不会让他以全小写字母登录,所以我决定修复它,但是,它不会登录在,它只是重定向到我的消息“发生意外错误”的登录。

它通过用户名检查,但不检查密码,并且它不返回密码不正确。

我尝试创建一个新帐户,它仍然进入那个错误页面,但这一次,它实际上让我登录了,但不是你已经成功登录,现有用户无法登录,而是新的我做了。

而且我确实尝试了密码重置,它有效,但不会导致成功登录消息。

我所做的另一个更改是密码的哈希,因为我使用用户名密码 Salt,并且我从更改为$hash = hash('sha256',$Username.$Password.$Salt);$hash = hash('sha256',strtolower($Username).$Password.$Salt);因为当用户名是大写或小写时,它对密码检查有影响。

我的代码:

<?php
    /* Mysql data */
    $MysqlUsername = "root";
    $MysqlPassword = "*********";
    $MysqlHostname = "localhost";
    $MysqlDatabase = "teamgamersnet";
    $Salt = "******";
    $Username = $_POST['Username'];
    $Password = $_POST['Password'];
    $Remember = $_POST['Remember'];
    $Cookie = "TGN";
    $IP       = $_SERVER['REMOTE_ADDR'];
    if (empty($Username) || empty($Password)) { die("Please fill in all the fields"); }


    $hash = hash('sha256',strtolower($Username).$Password.$Salt);

    $Sql = new mysqli($MysqlHostname, $MysqlUsername, $MysqlPassword, $MysqlDatabase);
    if ($Sql->connect_error){ echo $Sql->connect_error; }
    $sUser = $Sql->real_escape_string($Username);
    $sPass = $Sql->real_escape_string($Password);
    $xPass = $Sql->real_escape_string($hash);


    $CheckUser = $Sql->query("SELECT Username FROM `users` WHERE `Username` = '".$sUser."'");
    $CheckPass = $Sql->query("SELECT Password FROM `users` WHERE `Username` = '".$sUser."'");
    $CheckActive = $Sql->query("SELECT Activated FROM `users` WHERE `Username` = '".$sUser."'");
    if ($CheckUser->num_rows == 0) { header("Location: /?p=Login&wrongusr=true"); die(); }
    $xCheckUser = $CheckUser->fetch_array(MYSQLI_ASSOC);
    $xCheckPass = $CheckPass->fetch_array(MYSQLI_ASSOC);
    $xCheckAct =  $CheckActive->fetch_array(MYSQLI_ASSOC);
    if ($xCheckAct['Activated'] == "false") { header("Location: /?p=Login&activate=true"); die(); }
    if(strtolower($Username) == strtolower($xCheckUser['Username'])) { // Check if username match
        if($hash == $xCheckPass['Password']) { // Check if password is correct
        if(isset($Remember)){
                setcookie ($Cookie."User", htmlspecialchars($Username));
                setcookie ($Cookie."Pass", $hash);
        }
        else
        {
                setcookie ($Cookie."User", htmlspecialchars($Username), time() + 3600);
                setcookie ($Cookie."Pass", $hash, time() + 3600);
        }
                header("Location: /?login=true"); // Send them to home page 
    }

    else
    {
        header("Location: /?p=Login&wrongpwd=true"); // Send them to home page 
    }
    header("Location: /?p=Login&unxer=true"); // Username error, Idk why
    }
?>
4

1 回答 1

3

默认字符集和排序规则是latin1and latin1_swedish_ci,因此默认情况下非二进制字符串比较不区分大小写。这意味着,如果您使用 搜索,您将获得所有以orcol_name LIKE 'a%'开头的列值。Aa

要使此搜索区分大小写,请确保其中一个操作数具有区分大小写或二进制排序规则。例如,如果要比较具有latin1字符集的列和字符串,则可以使用COLLATE运算符使任一操作数具有latin1_general_csorlatin1_bin排序规则。

您只需要使用or更改您的UsernamePassword字段的排序规则,然后它就会相应地工作。latin1_general_cslatin1_bin

于 2012-11-06T13:02:03.527 回答