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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
| <?php if( session_id()=='' ){ session_start(); } // démarrage SESSION
error_reporting(E_ALL); // SEULEMENT pendant les TESTS !
ini_set("display_errors", 1); // SEULEMENT pendant les TESTS !
// connexion a la bdd
$objetpdo = new PDO('mysql:host=dbxxxxxxxxx.hosting-data.io;dbname=dbsxxxxxx','dbuxxxxxx','xxxxxxxxx');
unset($_SESSION['islogged']);
unset($_SESSION['username']);
// --------------
// 1- INSCRIPTION
$err_inscription = array();
if(isset($_POST['inscriptionmembre']) )
{
if( !empty($_POST["username"]) && !empty($_POST["password1"]) && !empty($_POST["password2"]))
{
if($_POST["password1"] == $_POST["password2"])
{
// INSERT en bdd
$pdostat = $objetpdo->prepare('INSERT INTO basemotpasse (username, password1) VALUES(:username, :password1);');
$pdostat->bindvalue(':username',$_POST['username'],PDO::PARAM_STR);
$pdostat->bindvalue(':password1',password_hash($_POST["password1"],PASSWORD_DEFAULT),PDO::PARAM_STR);
$pdostat->execute();
// Mise en SESSION
$_SESSION['islogged'] = true;
$_SESSION['username'] = $row['username'];
// ATTENTION ! ON NE MET JAMAIS LE MOT DE PASSE EN SESSION !!
// on redirige vers l'espace membre
header('location:espace_membre.php');
exit();
} else {
$err_inscription[] = 'Les deux mots de passe sont différents.';
}
} else {
$err_inscription[] = 'Remplissez tous les champs obligatoires.';
}
}
// --------------
// 2- CONNEXION
$err_connexion = array();
if(isset($_POST['connexionmembre']) )
{
if( !empty($_POST['username']) && !empty($_POST['password1']) )
{
// requete : username existe ?
$pdostat = $objetpdo->prepare("SELECT username, password1 FROM basemotpasse WHERE username = :username");
$pdostat->bindvalue(':username',$_POST['username'],PDO::PARAM_STR);
$pdostat->execute();
if( $pdostat->rowCount()>0 ) // username OK
{
$row = $pdostat->fetch();
// on compare le mot de passe entré avec celui enregistré en bdd
if( password_verify($_POST['password1'], $row['password1']) ) // pwd OK
{
// Mise en SESSION
$_SESSION['islogged'] = true;
$_SESSION['username'] = $row['username'];
// ATTENTION ! ON NE MET JAMAIS LE MOT DE PASSE EN SESSION !!
// on redirige vers l'espace membre
header('location:espace_membre.php');
exit();
} else{
$err_connexion[] = 'Identifiant et/ou mot de passe incorrect.';
}
} else {
$err_connexion[] = 'Identifiant et/ou mot de passe incorrect.';
}
} else {
$err_connexion[] = 'Remplissez tous les champs obligatoires.';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Inscription, Connexion membres</title>
</head>
<body>
<h2>Inscription</h2>
<?php if( !empty($err_inscription) ){ ?>
<div class="error"><?php echo implode('<br/>', $err_inscription); ?></div>
<?php } ?>
<form action="inscription_connexion_membre.php" method="post">
<p>
<label>Identifiant :</label>
<input type="text" name="username" required />
</p>
<p>
<label>Mot de passe :</label>
<input type="password" name="password1" required />
</p>
<p>
<label>Retapez mot de passe :</label>
<input type="password" name="password2" required />
</p>
<p><input type="submit" name="inscriptionmembre" /></p>
</form>
<h2>Connexion</h2>
<?php if( !empty($err_connexion) ){ ?>
<div class="error"><?php echo implode('<br/>', $err_connexion); ?></div>
<?php } ?>
<form action="inscription_connexion_membre.php" method="post">
<p>
<label>Identifiant :</label>
<input type="text" name="username" required />
</p>
<p>
<label>Mot de passe :</label>
<input type="password" name="password1" required />
</p>
<p><input type="submit" name="connexionmembre" /></p>
</form>
</body>
</html> |
Partager