mercredi 22 avril 2015

Retrieving username and password from SQlite database

I'm using the below to check an SQLite database for a username and password, but for some strange reason, it's bringing back an error that the password is incorrect when I login on the website:

private function checkPasswordCorrectnessAndLogin()
{
    $sql = 'SELECT Username, Password
            FROM users
            WHERE Username = :Username
            LIMIT 1';
    $query = $this->db_connection->prepare($sql);
    $query->bindValue(':Username', $_POST['Username']);
    $query->execute();
    $result_row = $query->fetchObject();
    if ($result_row) {
        if (password_verify($_POST['Password'], $result_row->Password)) {
            $_SESSION['Username'] = $result_row->Username;
            $_SESSION['user_is_logged_in'] = true;
            $this->user_is_logged_in = true;
            return true;
        } else {
            $this->feedback = "Incorrect Password.";
        }
    } else {
        $this->feedback = "User Does Not Exist.";
    }

    //default return
    return false;
}

I have no error with the username, it just states that the password is incorrect yet it is not; could anybody shine any light on why I'm receiving this error? I'm using the db browser to insert username and passwords into the table...

Aucun commentaire:

Enregistrer un commentaire