Amélioration de la sécurité

ServeurDeTest
Noé GARNIER 2 years ago
parent 254f2f89d8
commit e2d4bbb256

@ -3,7 +3,6 @@
$rep = __DIR__ . '/../'; $rep = __DIR__ . '/../';
//BD //BD
$dsn = 'mysql:host=londres.uca.local; dbname=dbnogarnier1'; $dsn = 'mysql:host=londres.uca.local; dbname=dbnogarnier1';
$user = 'nogarnier1'; $user = 'nogarnier1';
$password = 'achanger'; $password = 'achanger';
@ -12,6 +11,9 @@ $password = 'achanger';
// $user = 'root'; // $user = 'root';
// $password = 'p'; // $password = 'p';
//Sel de hashage
$sel = "JeSuisUnSeldeHashageEtJeSuisUniqueEtTresSecuriseEtJeSuisTresLong";
//View //View
//Page //Page
$vues['main'] = 'View/src/pages/Main.php'; $vues['main'] = 'View/src/pages/Main.php';

@ -30,10 +30,10 @@ class Validation
return true; return true;
} }
public function ValidateUsername(string $username) : bool{ public function ValidateUsername(string $username) : bool{
if(!filter_var($username,FILTER_VALIDATE_REGEXP,array("options" => array( "regexp" => "^[^&=_'\-+;<>.]{1,18}$" )))) // if(!filter_var($username,FILTER_VALIDATE_REGEXP,array("options" => array( "regexp" => "^[^&=_'\-+;<>.]{1,18}$" ))))
{ // {
return false; // return false;
} // }
return true; return true;
} }
public function ValidatePassword(string $password) : bool{ public function ValidatePassword(string $password) : bool{

@ -46,20 +46,20 @@ class Controller
} }
private function signUp() { private function signUp() {
global $rep, $vues; global $rep, $vues, $sel;
try { try {
$gateway = new JoueurGateway($this->con); $gateway = new JoueurGateway($this->con);
$validation = new Validation(); $validation = new Validation();
if (! $validation->ValidateEmail($_REQUEST['email'])) { if (! $validation->ValidateEmail($_REQUEST['email'])) {
throw (new Exception("Email non valide")); throw (new Exception("Email non valide"));
} }
$password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT);
if(! $validation->ValidateUsername($_REQUEST['username'])){ if(! $validation->ValidateUsername($_REQUEST['username'])){
throw(new Exception("Pseudo non valide")); throw(new Exception("Pseudo non valide"));
} }
if(! $validation->ValidatePassword($_REQUEST['password'])){ if(! $validation->ValidatePassword($_REQUEST['password'])){
throw(new InvalidMdpException("Mot de passe non valide")); throw(new InvalidMdpException("Mot de passe non valide"));
} }
$password = password_hash($_REQUEST['password']+$selNoHash, PASSWORD_DEFAULT);
$joueur = new Joueur($_REQUEST['email'], $_REQUEST['username'], $password); $joueur = new Joueur($_REQUEST['email'], $_REQUEST['username'], $password);
$gateway->insert($joueur); $gateway->insert($joueur);
$_SESSION['connected'] = 'true'; $_SESSION['connected'] = 'true';
@ -69,7 +69,7 @@ class Controller
} }
} }
private function login(){ private function login(){
global $rep, $vues; global $rep, $vues, $sel;
try { try {
$gateway = new JoueurGateway($this->con); $gateway = new JoueurGateway($this->con);
$joueur = $gateway->getJoueurByEmail($_REQUEST['email']); $joueur = $gateway->getJoueurByEmail($_REQUEST['email']);
@ -77,7 +77,7 @@ class Controller
throw new JoueurNotFoundException("Joueur introuvable"); throw new JoueurNotFoundException("Joueur introuvable");
} }
$mdp = $gateway->getMdpByEmail($_REQUEST['email']); $mdp = $gateway->getMdpByEmail($_REQUEST['email']);
if (password_verify($mdp, $_REQUEST['password'])){ if (password_verify($mdp, $_REQUEST['password']+$sel)){
throw new InvalidMdpException("Mot de passe invalide"); throw new InvalidMdpException("Mot de passe invalide");
} }
$_SESSION['connected'] = 'true'; $_SESSION['connected'] = 'true';

@ -6,6 +6,9 @@ Autoload::charger();
$con = new Connection($dsn, $user, $password); $con = new Connection($dsn, $user, $password);
$control = new Controller($con); $control = new Controller($con);
session_unset(); session_regenerate_id(true);
session_destroy(); // session_unset();
$_SESSION = null; // session_destroy();
// $_SESSION = null;
//https://a-pellegrini.developpez.com/temp/tutoriels/php/security/session/#III.2
Loading…
Cancel
Save