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
|
<?php
include('header.html');
include('../trombi/accesBD.Script.php');
$BD = new accesBD;
$bdd = $BD->connexionMysqliUti();
$username = $password = "";
$username_err = $password_err = "";
$encryption_key = strval(fopen("../GestionUtilisateur/CLEMDP.txt","r"));
function decrypt($encrypted_string, $encryption_key) {
$iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$decrypted_string = mcrypt_decrypt(MCRYPT_BLOWFISH, $encryption_key, $encrypted_string, MCRYPT_MODE_ECB, $iv);
return $decrypted_string;
}
function encrypt($pure_string, $encryption_key) {
$iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$encrypted_string = mcrypt_encrypt(MCRYPT_BLOWFISH, $encryption_key, utf8_encode($pure_string), MCRYPT_MODE_ECB, $iv);
return $encrypted_string;
}
if($_SERVER["REQUEST_METHOD"] == "POST"){
$username = $_POST["username"];
$password = $_POST['password'];
// Check des informations par rapport à la base
if(empty($username_err) && empty($password_err)){
$req = "SELECT username, password
FROM users
WHERE username = ?
AND ID_MODULE = 1";
if($stmt = mysqli_prepare($bdd, $req)){
mysqli_stmt_bind_param($stmt, "s", $param_username);
$param_username = $username;
if(mysqli_stmt_execute($stmt)){
mysqli_stmt_store_result($stmt);
// Check si l'username existe
if(mysqli_stmt_num_rows($stmt) == 1){
mysqli_stmt_bind_result($stmt, $username, $hashed_password);
if(mysqli_stmt_fetch($stmt)){
$fin = decrypt($hashed_password, $encryption_key);
echo $hashed_password."<br>";
echo $fin."<br>";
if($password == $fin){
// Check password par rraport au username
session_start();
$_SESSION['username'] = $username;
$_SESSION['connexion'] = 1;
//header("location: PageAccueil.php");
} else{
$password_err = "Le password que vous avez entrer n'ai pas valide.";
}
}
} else{
$username_err = 'Pas de compte trouvé pour cet utilisateur';
}
}
}
mysqli_stmt_close($stmt);
}
mysqli_close($bdd);
}
?> |
Partager