Advertisement
Guest User

Untitled

a guest
Oct 9th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. <?php
  2. session_start();
  3. require_once('bdd.php');
  4.  
  5. if(isset($_POST["valider"])) {
  6. if(!empty($_POST["username"]) && !empty($_POST["password"]) && !empty($_POST["password_confirm"])) {
  7. $username = htmlentities($_POST['username']);
  8. $password = htmlentities($_POST['password']);
  9. $password_confirm = htmlentities($_POST['password_confirm']);
  10. // Récupération de l'utilisateur (vérification si il éxiste déjà)
  11. $req = $bdd->prepare('SELECT id, password FROM users WHERE identifiant = :username');
  12. $req->execute(array(
  13. 'username' => $username));
  14. $resultat = $req->fetch();
  15. if($resultat) {
  16. $_SESSION['message'] = "Cet identifiant est déjà utilisé";
  17. header('Location: signup.php');
  18. exit;
  19. }
  20. if($password != $password_confirm) {
  21. $_SESSION['message'] = "Les mots de passe ne correspondent pas";
  22. header('Location: signup.php');
  23. exit;
  24. }
  25. $hash_password = password_hash($password, PASSWORD_DEFAULT);
  26.  
  27. $req = $bdd->prepare('INSERT INTO users(identifiant, password) VALUES(:username, :password)');
  28. $req->execute(array(
  29. 'username' => $username,
  30. 'password' => $hash_password));
  31. header('Location: signin.php');
  32. exit;
  33. } else {
  34. $_SESSION["message"] = "L'identifiant ou le mot de passe n'a pas été saisie.";
  35. header('Location: signup.php');
  36. exit;
  37. }
  38. } else {
  39. header('Location: signup.php');
  40. exit;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement