亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Oop PHP 登錄檢查散列密碼

Oop PHP 登錄檢查散列密碼

PHP
婷婷同學_ 2023-07-08 20:29:34
我的問題是在課堂上檢查哈希密碼。這是錯誤:致命錯誤:未捕獲錯誤:無法在 Auth.php:51 中使用 PDOStatement 類型的對象作為數組堆棧跟蹤:#0 index.php(19): Auth->login() #1 {main} 在線 Auth.php 中拋出51if(isset($_POST['login'])) {    $username = $_POST['username'];    $password = $_POST['password'];    #LINE 19    $ui->login($username, $password); }這是我的代碼public function login ( $username, $password ) {    $u_login = $this->conn->prepare("SELECT * FROM korisnici WHERE username = :username");    $u_login->bindValue(':username', $username);    $u_login->execute();    $u_login->fetch(PDO::FETCH_ASSOC);    # LINE 51    $u_v_PASS = password_verify($password, $u_login['password']);      if($u_v_PASS->count()) {        echo 'uspesno';    } else {     }}
查看完整描述

1 回答

?
米琪卡哇伊

TA貢獻1998條經驗 獲得超6個贊

您正在使用 PDOStatement 對象執行提取,但不存儲該提取的結果。相反,您在 PDOStatement 對象本身中查找密碼。嘗試:


public function login ( $username, $password ) {

    $u_login = $this->conn->prepare("SELECT * FROM korisnici WHERE username = :username");

    $u_login->bindValue(':username', $username);

    $u_login->execute();


    /*

     * Now that the prepared statement has been built and executed, we can

     * try to fetch a matching user and store it as $user - this will be an

     * array if successful or boolean false if not.

     */

    $user = $u_login->fetch(PDO::FETCH_ASSOC);


    /* Check that $user is not false and the password_verify returns boolean

     * true when comparing the password to the hashed password stored in the

     * database.

     */

    if ($user && password_verify($password, $user['password'])) {

        // User was found and password matched

    }

}


查看完整回答
反對 回復 2023-07-08
  • 1 回答
  • 0 關注
  • 136 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號