密码验证身份验证错误的问题

时间:2019-02-01 17:25:04

标签: php

我正在尝试用php的PDO语法实现passwordverify。注册后,我的密码会被散列。当我点击登录这个错误弹出

  

解析错误:语法错误,意想不到 ';',期待 '' 或 ')' 在   C:\ XAMPP \ htdocs中\尝试在线25上\ authenticate.php

这是我的authenticate.php

<?php 
    require 'database-config.php';

    session_start();

    $username = "";
    $password = "";

    if(isset($_POST['username'])){
        $username = $_POST['username'];
    }
    if (isset($_POST['password'])) {
        $password = $_POST['password'];

    }

    echo $username ." : ".$password;

    $q = 'SELECT * FROM isalonusers WHERE username=:username AND password=:password';

    $query = $dbh->prepare($q);



    $query->execute(array(':username' => $username, ':password' => password_verify($_POST['password'], $password['password']));


    if($query->rowCount() == 0){
        header('Location: index.php?err=1');
    }else{

        $row = $query->fetch(PDO::FETCH_ASSOC);

        session_regenerate_id();
        $_SESSION['sess_user_id'] = $row['id'];
        $_SESSION['sess_username'] = $row['username'];
        $_SESSION['sess_name'] = $row['name'];
        $_SESSION['sess_phone_number'] = $row['phone_number'];
        $_SESSION['sess_gender'] = $row['gender'];
        $_SESSION['sess_address'] = $row['address'];
        $_SESSION['sess_occupation'] = $row['occupation'];
        $_SESSION['sess_birth_date'] = $row['birth_date'];
        $_SESSION['sess_userrole'] = $row['user_type'];

        echo $_SESSION['sess_userrole'];
        session_write_close();

        if( $_SESSION['sess_userrole'] == "admin"){
            header('Location: adminhome.php');
        }else{
            header('Location: index.php?err=1');
        }


    }


?>  

验证密码时我的语法错误是什么?

1 个答案:

答案 0 :(得分:-1)

meat => beef, pork, poultry
beef => steak, hamburger, filet
pork => hot dog, ham, bacon
poultry => chicken, hen, turkey

第25行缺少$query->execute(array(':username' => $username, ':password' => password_verify($_POST['password'], $password['password'])));

更新

http://php.net/manual/en/function.password-verify.php

根据文档)将给出布尔值。您只需对用户输入的密码进行哈希处理,然后与db password比较即可。 如下所示。

password_verify