password_verify无法与Bcrypt验证password_hash

时间:2015-05-02 19:16:39

标签: php hash passwords bcrypt

我在让password_verify确认我的哈希密码时遇到了一些问题。 这是我的登录信息:

if (isset($_POST["login-button-front"]))
{
    // IF VALUE IS GIVEN
    if (isset($_POST["user-password"]) && ($_POST["user-email"])){
        $user_email = $_POST["user-email"];

        // QUERY DATABASE TO VERIFY LOGIN INFORMATION
        $query_password = $db->prepare("SELECT password, user_session FROM login WHERE email = :user_email");
        $query_password->execute(array(':user_email' => $user_email));
        $password_row = $query_password->fetchAll();

        // CHECK PASSWORD
        $password = $_POST["user-password"];
        $password_hash = $password_row[0]["password"];

        if(password_verify($password, $password_hash)){
            $_SESSION['user'] = $password_row['user_session'];
            require 'members.php';
        }
        // RESPOND IF WRONG INFORMATION GIVEN
        else{
            $login_wrong = "The username and/or password you entered is incorrect. Please try again.";
            require 'front_page.php';
        }
    }
    // RESPOND IF NO INFORMATION GIVEN
    else{
        $login_wrong = "You must enter a valid username and password to login. Need an account? Register below.";
        require 'front_page.php';
    }
}

这是我的注册:

$password = password_hash($_POST['password1'], PASSWORD_DEFAULT);

0 个答案:

没有答案