Bonsoir all ! Ou bonjour ! :)

J'ai quelque soucis avec PHP "password_verify" ! C'est pour un formulaire de connexion !

Voici mon CODE :

                        $db = App::getDatabase();
                        $user = $db->query('SELECT * FROM users WHERE username = :username AND confirm_at IS NOT NULL', [$_POST['username']])->fetch();

                        if(password_verify($_POST['password'], $user->password))
                        {
                            $_SESSION['auth'] = $user;
                            header('Location: account.php');
                            exit();
                        } else {
                            echo '<div class="form-error"><ul><li>Identifiant incorrecte.</li></ul></div>';
                        }

Voici l'érreur qu'il me dit :
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not
PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in

Voilà Voilà J'espère que j'ai tout dit ^^

J'ai suivis comme sur le tuto et cela ne fonctionne pas.... Je bloque sur ce problème.... :( Et je vous remercie tous de vos réponse en avance :D

2 réponses


Iteck
Auteur

Et quand je fais comme ça :

                    if(isset($_POST['submit-login-user']))
                    {
                        $db = App::getDatabase();
                        $user = $db->query('SELECT * FROM users WHERE username = ? AND confirm_at IS NOT NULL', [$_POST['username']])->fetch();

                        if(password_verify($_POST['password'], $user->password))
                        {
                            $_SESSION['auth'] = $user;
                            header('Location: account.php');
                            exit();
                        } else {
                            echo '<div class="form-error"><ul><li>Identifiant incorrecte.</li></ul></div>';
                        }
                    }

Voici l'érreur :
Notice: Trying to get property of non-object in

Test avec ce code

 if(isset($_POST['submit-login-user']))
                    {
                        $db = App::getDatabase();
                        $user = $db->prepare('SELECT * FROM users WHERE username = ?');
                        $user->execute(array($_POST['username']));
                        $return = $user->fetchAll()[0];

                        if(password_verify($_POST['password'], $return->password))
                        {
                            $_SESSION['auth'] = $user;
                            header('Location: account.php');
                            exit();
                        } else {
                            echo '<div class="form-error"><ul><li>Identifiant incorrecte.</li></ul></div>';
                        }
                    }