Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- require_once('bdd.php');
- if(isset($_POST["valider"])) {
- if(!empty($_POST["username"]) && !empty($_POST["password"]) && !empty($_POST["password_confirm"])) {
- $username = htmlentities($_POST['username']);
- $password = htmlentities($_POST['password']);
- $password_confirm = htmlentities($_POST['password_confirm']);
- // Récupération de l'utilisateur (vérification si il éxiste déjà)
- $req = $bdd->prepare('SELECT id, password FROM users WHERE identifiant = :username');
- $req->execute(array(
- 'username' => $username));
- $resultat = $req->fetch();
- if($resultat) {
- $_SESSION['message'] = "Cet identifiant est déjà utilisé";
- header('Location: signup.php');
- exit;
- }
- if($password != $password_confirm) {
- $_SESSION['message'] = "Les mots de passe ne correspondent pas";
- header('Location: signup.php');
- exit;
- }
- $hash_password = password_hash($password, PASSWORD_DEFAULT);
- $req = $bdd->prepare('INSERT INTO users(identifiant, password) VALUES(:username, :password)');
- $req->execute(array(
- 'username' => $username,
- 'password' => $hash_password));
- header('Location: signin.php');
- exit;
- } else {
- $_SESSION["message"] = "L'identifiant ou le mot de passe n'a pas été saisie.";
- header('Location: signup.php');
- exit;
- }
- } else {
- header('Location: signup.php');
- exit;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement