Using password_verify on existing password

前端 未结 2 1746
情话喂你
情话喂你 2020-12-20 03:37

I\'m trying to check the password and username of someone before they log in to my website. The passwords are all stored in password_hash($password1, PASSWORD_BCRYPT);

2条回答
  •  别那么骄傲
    2020-12-20 04:22

    I fixed the issue.. I was using password_verify incorrectly.

    prepare("SELECT `password` FROM `accounts` WHERE username = ?")) {
    
        /* Bind parameters: s - string, b - blob, i - int, etc */
        $stmt -> bind_param("s", $username);
    
        /* Execute it */
        $stmt -> execute();
    
        /* Bind results */
        $stmt -> bind_result($result);
    
        /* Fetch the value */
        $stmt -> fetch();
    
        /* Close statement */
        $stmt -> close();
    }
    
    
    if(password_verify($password1, $result))
    {
        session_start();
        $_SESSION['loggedin'] = true;
        $_SESSION['username'] = $username;
    
       echo '';
    }else{
        echo ''; 
    }
    
    $mysqli->close(); 
    ?>
    

提交回复
热议问题