Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP和MYSQL密码验证问题_Php_Mysql_Hash - Fatal编程技术网

PHP和MYSQL密码验证问题

PHP和MYSQL密码验证问题,php,mysql,hash,Php,Mysql,Hash,基本上。我在解密我的密码时遇到问题。这是一个虚拟项目,在mysql中完成。我知道它现在被贬值了,我正在学习mysqli和PDO 我可以完美地散列密码,如下所示: $password = password_hash("$password1", PASSWORD_DEFAULT); $password = substr( $hash, 0, 60 ); 我的数据库密码字段设置为CHAR255,因此我被难住了。。目前,我的密码\u验证运行方式如下: // Define $username a

基本上。我在解密我的密码时遇到问题。这是一个虚拟项目,在mysql中完成。我知道它现在被贬值了,我正在学习mysqli和PDO

我可以完美地散列密码,如下所示:

$password = password_hash("$password1", PASSWORD_DEFAULT);
    $password = substr( $hash, 0, 60 );
我的数据库密码字段设置为CHAR255,因此我被难住了。。目前,我的密码\u验证运行方式如下:

// Define $username and $password
   if (isset($_POST["action"]) && $_POST["action"]=="login") 
   {
    $username =$_POST["username"];
    $password =$_POST["password"];

// SQL query to fetch information of registered users and finds user match.
//searches table for a username and password matching post data 
    $dbQuery = "SELECT * FROM users WHERE username = '$username';";
    $dbResult = mysql_query($dbQuery);
    $dbRow=mysql_fetch_array($dbResult);

    $username = $dbRow["username"];

// checks if user exists from sql
    if(mysql_num_rows($dbResult)==0)
    {
        echo '<script language="javascript">';
        echo 'alert("Oops! No user exists under that username!")';
        echo '</script>';
    }

    $hash = $dbRow['password'];
    // checks if password matches stored hash

    if (password_verify('$password', $hash)) {
    echo 'Password is valid!';
} else {
    echo 'Password is valid!';
}
   }

任何帮助都将不胜感激!谢谢

您的第二个echo“密码确实有效!”;应为echo“密码无效!”;此外,当您想要的是变量时,您有一个单引号字符串“$password”$password@IMSoP是的,很抱歉,它没有说无效,我在那里有散列,这样我就可以看到密码是否正在从表中检索,好的,并复制和粘贴,而不用考虑。我试过密码有没有“但是什么都没有..等等,这条线在那里干什么$密码=substr$hash,0,60;你不能删减散列,它将不再是相同的散列。@IMSoP我把这个放进去是因为我在某个地方读到我需要限制它的大小,即使我删除这一行,仍然没有运气