Jump to content

password_verify()


noobdood

Recommended Posts

i tired the password_verify() but im not doing it right i think. got a warning:

 

 

 

 password_verify() expects exactly 2 parameters, 1 given

 

trying to login code:

ob_start();
session_start();

if(isset($_POST['login']))
{
    $email = $_POST['email'];
    $password = $_POST['pass'];
    
     require "connection.php";
    
    $emails = mysqli_real_escape_string($con, $email);
    $query = "SELECT id, name, email, password, salt FROM users WHERE email = '$emails';";
    
    $result = mysqli_query($con, $query);
    
    if(mysqli_num_rows($result) == 0) // User not found. So, redirect to login_form again.
    {
        echo "<script>alert(\"User does not exist!\")</script>";
    }
    
    $userData = mysqli_fetch_array($result, MYSQLI_ASSOC);
    $hash = $userData['password'];
    
    if(password_verify($password) != $hash)
    {
        echo "<script>alert(\"Incorrect Password!\")</script>";
    }else{
        session_regenerate_id();
        $_SESSION['sess_user_id'] = $userData['id'];
        $_SESSION['sess_name'] = $userData['name'];
        session_write_close();
        header('Location: home.php');
    }
}

Link to comment
https://forums.phpfreaks.com/topic/288616-password_verify/
Share on other sites

Please read the manual. Or just use common sense: You verify a password against a given hash, so it's only natural that there are two parameters. The first parameter is for the password, the second is for the hash. If the password matches the hash, the function returns true, otherwise it returns false.

Link to comment
https://forums.phpfreaks.com/topic/288616-password_verify/#findComment-1480133
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.