Can`t make password_verify() work

140
December 20, 2017, at 01:24 AM

Okay, I hope it is not duplicate, but other posts didn`t help me.

I hash password before it is store into DB. When I want to get it back and compare with user input I always get "password does not match". I tried a lot of fixes but nothing seems to work. May be the problem is with my syntax, I am not good with php.

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
    if (password_verify($RegisteredPass, $row['pass']))
       {
           echo "tchd";
           echo "ID:".$row['id'] ."|Name:".$row['name']. "|User:".$row['user'];
           }
       else{
           echo "pass doesn`t match";
       }
    }
} else {
    echo "user not found";
}

Hashing password

$hassedPassword = password_hash($password, PASSWORD_DEFAULT, ['cost' => 12]);

I am not very concern about security, because it is just for a project. I just need to make it work.

EDIT:

I changed while loop as was in "duplicate". Still does not work. Any ideas why.

$sql = "SELECT pass, id, name, user FROM unityTut WHERE user='".$RegisterUser."'";
 $result = $conn->query($sql);
        if ($result->num_rows === 1) {
            $row = $result->fetch_array(MYSQLI_ASSOC);
            if (password_verify($RegisteredPass, $row['pass'])) {
                //Password matches, so create the session

echo "Match";
            }else{
                echo  "The username or password do not match";
            }
Answer 1

So it works now!

Code for login:

$sql = "SELECT pass, id, name, user FROM unityTut WHERE user='".$RegisterUser."'";
$result = $conn->query($sql);
if ($result->num_rows === 1) {
    $row = $result->fetch_array(MYSQLI_ASSOC);
    if (password_verify($RegisteredPass, $row['pass'])) {
        echo "Match";
    }else{
        echo  "The username or password do not match";
    }
// ...

VARCHAR(255) Seems to do the trick, but I had to delete all records and register new user. That seems to do the trick too.

READ ALSO
Add filename to YouTube API upload

Add filename to YouTube API upload

I've been getting a "Raw: Unknown" filename for the videos I've been uploading to YouTube using the APILooking at the YouTube API Library, I've seen that there is a

222
php looping through array to create multi dimensional array

php looping through array to create multi dimensional array

I am trying to loop though an existing multidimensional array grabbing certain values based on a key

101
jQuery AJAX function - data not being passed

jQuery AJAX function - data not being passed

Not sure what I'm doing wrong here but I have the following AJAX functionconsole

149