Bonjour,
L'affichage du formulaire dans la page "index.php?p=login fonctionne. Mais quand je soumets le formulaire login.php, j'obtiens des warnings : undefined array key "usernames" et undefined array key "passwords". Or, le var_dump($POST) affiche :
array(2) { ["username"]=> string(4) "demo" ["password_"]=> string(4) "demo" }
Ci-dessus le fichier Login.php :
<?php
use Core\Auth\DBAuth;
use Core\HTML\BootstrapForm;
$form = new BootstrapForm($_POST);
if(!empty($_POST)) {
$auth = new DBAuth(App::getInstance()->getDb());
var_dump($_POST);
if($auth->login($_POST["username"], $_POST["password"])) {
die('Connecté');
}
else {
die('Non connecté');
}
}
//$form = new BootstrapForm($_POST);
?>
<form method = "POST" style="margin-top: 20px;">
<?= $form->input('username', 'Pseudo'); ?>
<?= $form->input('password', 'Mot de passe', ['type' => 'password']); ?>
<?= $form->submit() ?>
</form>
et la classe DBAuth :
<?php
namespace Core\Auth;
use Core\Database\Database;
class DBAuth {
private $db;
public function __construct(Database $db) {
$this->db = $db;
}
/**
* @param $username
* @param $password
* return boolean
*/
public function login($username, $password) {
$user = $this->db->prepare(
"SELECT * FROM users WHERE username = ?",
[$username],
null,
true
);
if($user) {
return $user->password = sha1($password);
}
else {
return false;
}
}
public function logged() {
return isset($_SESSION['auth']);
}
}
?>
Ce que j'obtiens
aarray(2) { ["username"]=> string(4) "demo" ["password"]=> string(4) "demo" }
Warning: Undefined array key "username" in C:\xampp\htdocs\www\POO\Blog\pages\users\login.php on line 11
Warning: Undefined array key "password" in C:\xampp\htdocs\www\POO\Blog\pages\users\login.php on line 11
Non connecté