Php 奇怪的密码\u散列问题

Php 奇怪的密码\u散列问题,php,php-password-hash,Php,Php Password Hash,因此,我使用的脚本与前一段时间完全相同,出于某种原因,当我移动到我的新域并托管它时,出现了非常奇怪的问题,我创建了一个用户并让hm尝试登录,这对他不起作用。我从一个随机test.php文件中获得了一个新的哈希值,该php: <?php /** * In this case, we want to increase the default cost for BCRYPT to 12. * Note that we also switched to BCRYPT, which will a

因此,我使用的脚本与前一段时间完全相同,出于某种原因,当我移动到我的新域并托管它时,出现了非常奇怪的问题,我创建了一个用户并让hm尝试登录,这对他不起作用。我从一个随机test.php文件中获得了一个新的哈希值,该php:

<?php
/**
 * In this case, we want to increase the default cost for BCRYPT to 12.
 * Note that we also switched to BCRYPT, which will always be 60 characters.
 */
$options = [
    'cost' => 9,
];
echo password_hash("His Pass", PASSWORD_BCRYPT, $options)."\n";
?>
提取功能:

//Create a new function named user_login;
function user_login($username = false, $password = false) {

    //Fetch for the username and password applied;
    $st = fetch("SELECT username,password,email,image FROM users WHERE username = :username",array(":username"=>$username));

    //If a row was found continue
    if($st != 0) {

        $storedhash = $st[0]['password'];

        if (password_verify($password, $storedhash)) {

            //Set a new username session and set it the username;
            $_SESSION['username'] = $username;
            $_SESSION['email'] = $st[0]['email'];
            $_SESSION['image'] = $st[0]['image'];

            if($username == 'admin') {
                $_SESSION['role'] = 'admin';
            } else {
                $_SESSION['role'] = 'user';
            }

        }

    }

    //If no errors happened Make the $valid true;
    return true;

    $dontaddtry = true;

}
//Create a new function named fetch;
function fetch($sql = false,$bind = false,$obj = false) {

    //Prepare The SQL Query;
    $query = Connect()->prepare($sql);

    //Execute Binded Query;
    $query->execute($bind);

    //While Fetching Results;
    while($result = $query->fetch(PDO::FETCH_ASSOC)) {

        //Add a row to the results respectiveley;
        $row[] = $result;

    }

    //If there are no rows;
    if(!empty($row)) {

        //Make it an object;
        $row = ($obj)? (object) $row : $row;
    } else {

        //Else row is false;
        $row = false;
    }

    //If no errors happened Make $row true;
    return $row;

}
连接功能:

//Create a new function named LoggedIn, And apply database info;
function Connect($host = 'localhost',$username = 'x',$password = 'x',$dbname = 'x') {

    //Try execute the PHP with no errors;
    try {

        //Create a PDO Session;
        $con = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);

        //Session Attributes;
        $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $con->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

    }

    //Catch all PDOException errors;
    catch (PDOException $e) {

        //If any errors print result;
        echo "<code><pre>".print_r($e)."</pre></code>";

        //Make the PDO session false;
        $con = false;
    }

    //If no errors happened Make the PDO session true;
    return $con;
}
//创建一个名为LoggedIn的新函数,并应用数据库信息;
函数连接($host='localhost',$username='x',$password='x',$dbname='x')){
//尝试执行PHP,没有错误;
试一试{
//创建PDO会话;
$con=newpdo(“mysql:host=$host;dbname=$dbname”,$username,$password);
//会话属性;
$con->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_异常);
$con->setAttribute(PDO::ATTR_EMULATE_PREPARES,false);
}
//捕获所有异常错误;
捕获(PDO$e){
//如果有任何错误,打印结果;
回显“
”。打印($e)。“
”; //使PDO会话为假; $con=假; } //如果没有发生错误,则使PDO会话为真; 返回$con; }

注:如果你想在我的网站上注册一个账号,请告诉我,我会创建一个临时账号。

确保你的新主机的php版本
password\u hash
至少需要
PHP5.5.0

您可以通过以下代码检查当前的PHP版本


确保您的主机是新主机的php版本
password\u hash
至少需要
PHP5.5.0

您可以通过以下代码检查当前的PHP版本



数据库中的哈希值是正确的还是空字符串?用来存储散列的列类型是什么?当然是正确的,它是Varchar(60)。有这么多代码,很难找出确切的问题,调试散列可能很棘手,因为您不知道它是否正确。只是一个想法:为什么不暂时切换您的代码以明文形式存储您的密码,执行更新thingamajig,然后确保它实际上存储了正确的密码。哈希值在数据库中是正确的还是空字符串?用来存储散列的列类型是什么?当然是正确的,它是Varchar(60)。有这么多代码,很难找出确切的问题,调试散列可能很棘手,因为您不知道它是否正确。只是一个想法:为什么不暂时切换您的代码以明文形式存储您的密码,执行update thingamajig,然后确保它实际存储了正确的密码。是的ofc im 5.6,否则一半时间不会工作。是的ofc im 5.6,否则一半时间不会工作。
//Create a new function named LoggedIn, And apply database info;
function Connect($host = 'localhost',$username = 'x',$password = 'x',$dbname = 'x') {

    //Try execute the PHP with no errors;
    try {

        //Create a PDO Session;
        $con = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);

        //Session Attributes;
        $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $con->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

    }

    //Catch all PDOException errors;
    catch (PDOException $e) {

        //If any errors print result;
        echo "<code><pre>".print_r($e)."</pre></code>";

        //Make the PDO session false;
        $con = false;
    }

    //If no errors happened Make the PDO session true;
    return $con;
}
<?php
    echo 'Current PHP version: ' . phpversion();
?>