mysqli_fetch_array返回截断值

时间:2015-09-15 05:03:05

标签: php mysqli truncation

因此,当我尝试将$ testpass与$ encpass进行比较时,我每次都会失败,因为$ encpass被mysqli_fetch_array函数截断。我可能需要在PHP设置或MYSQL数据库的设置中更改设置。我的密码在数据库中存储为varchar(255),但是在获得下面的代码后我会将其更改为varchar(128)。

<?php

    include 'includes/connection.php';
    $user=$_POST['User'];
    $pass=$_POST['pass'];

    function hashpass($red,$algo){
        $hash=hash($algo,$red);
        return $hash;
    }
    if($user!=NULL){
        $query="SELECT password FROM user_data WHERE User_Name='".$user."' LIMIT 1";
        if($query!=NULL){
            $result = mysqli_query($conn, $query) or die (mysqli_error($conn)." query=".$query);
            while($user_data = mysqli_fetch_array($result, MYSQLI_ASSOC)){
                $encpass=$user_data['password'];
            }
        }else{
            echo "ERROR 400";
        }
        $testpass=hashpass($pass,"sha512");
        if($testpass==$encpass){
            //login();
            echo "PASS";
        }else{
            echo "result:= ";
            var_dump($result);
            echo "<br />encpass:= ";
            var_dump($encpass);
            echo "<br />query:= ";
            var_dump($query);
            echo "<br />testpass:= ";
            var_dump($testpass);
            echo "<br />";
        }
    }else{
        echo"No such user";
    }
?>

以上结果如下:

result:

object(mysqli_result)[2]
public 'current_field' => null
public 'field_count' => null
public 'lengths' => null
public 'num_rows' => null
public 'type' => null


encpass:

string '78ddc8555bb1677ff5af75ba5' (length=25)


query:

string 'SELECT password FROM user_data WHERE User_Name='test2' LIMIT 1' (length=62)


testpass:

string '78ddc8555bb1677ff5af75ba5fc02cb30bb592b0610277ae15055e189b77fe3fda496e5027a3d99ec85d54941adee1cc174b50438fdc21d82d0a79f85b58cf44' (length=128)

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

你可能打错了255到25?发布数据库结构的转储......