This question already has an answer here:
- Secure hash and salt for PHP passwords 14 answers
From my understanding so far (at least I think) the password_hash() function generates a hash based on the algorithm in use, cost and the salt. While the password_verify uses the information provided from e.g. password_hash($pass, PASSWORD_BCRYPT, array('cost'=>10))
to check if the retuned value is true or false as it contains all the information necessary for verifying.
I previously used
$SQL_Query = "SELECT * FROM DB_Table WHERE userName = '".$username."'" AND password = $ID;
which would work as they were stored in plain text and could return true whereas logically it won't work this time around.
I have came across similar questions where they use static passwords in explanations such as
<?php
$to_verify = '$2y$07$BCryptRequires22Chrcte/VlQH0piJtjXl.0t1XkA8pw9dMXTpOq';
if (password_verify('rasmuslerdorf', $to_verify))
{
echo 'Password is valid!';
} else
{
echo 'Wrong password.';
}
The concept I am having trouble understanding is how one would check the password input against the hashed value if it is stored in a database rather than the being known by the page at that point in time? I recently got help regarding storing the values which was a silly error on my part but I guess this isn't clicking with me as well as I hoped for the moment.