La fonction password_verif
Bonjour, voici mon code :
class/userManager.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
<?php
class userManager {
private $_db;
public function __construct(PDO $db) {
$this->setDb($db);
}
public function setDb($dbh) {
$this->_db = $dbh;
}
public function insertUser(User $user) {
$sql = 'INSERT INTO user (pseudo, pass) VALUES (:pseudo, :pass)';
$pseudo = $user->getPseudo());
$pass = $user->getPass());
$userpass_form = password_hash($pass, PASSWORD_DEFAULT);
$stmnt = $this->_db->prepare($sql);
$stmnt->bindParam(':pseudo', $pseudo);
$stmnt->bindParam(':pass', $userpass_form);
$stmnt->execute();
}
public function getPseudo($pseudo) {
$sql = 'SELECT pseudo FROM user WHERE pseudo = :pseudo';
$stmnt = $this->_db->prepare($sql);
$stmnt->bindParam(':pseudo', $pseudo);
$stmnt->execute(array(
':pseudo' => $pseudo
));
$count = $stmnt->rowCount();
if($count <= 0) {
return true;
}
else {
return false;
}
}
public function getUser($pseudo) {
$sql = 'SELECT pseudo, pass FROM user WHERE pseudo = :pseudo AND pass = :pass';
$stmnt = $this->_db->prepare($sql);
$stmnt->bindParam(':pseudo', $pseudo);
$stmnt->bindParam(':pass', $pass);
$stmnt->execute(array(
':pseudo' => $pseudo,
':pass' => $pass
));
$data = $stmnt->fetch(PDO::FETCH_ASSOC);
if(password_verify($pass, $data['pass'])) {
return true;
}
else {
return false;
}
}
} |
process/process_login.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
<?php
require('includes/inc_connexion.php');
require('class/userManager.php');
if(isset($_POST['submit_form'])) {
$pseudo_form = trim($_POST['pseudo_form']);
$userpass_form = trim($_POST['userpass_form']);
if((isset($pseudo_form)) AND (isset($userpass_form))) {
$manager = new userManager($db);
if(!$manager->getUser($pseudo_form, $userpass_form)) {
$message = '<p class="error">Mot de passe incorrect !</p>';
}
else {
$message = '<p class="success">Accès OK !</p>';
}
}
else {
$message = '<p class="error">Identifiants incorrects</p>';
}
} |
Quand je veux me connecter j'ai ce message d'erreur ligne 79 (userManager.php) -> Notice: Trying to access array offset on value of type bool
Merci pour votre aide & bonne journée