Advertisement
Guest User

Untitled

a guest
Mar 31st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.39 KB | None | 0 0
  1. <?php
  2.     require_once('resources/template/top.php');
  3.     if(isset($_POST['submit']))
  4.     {
  5.         if(!empty($_POST['username']) && !empty($_POST['password']))
  6.         {
  7.             $username = htmlspecialchars($_POST['username']);
  8.             $password = htmlspecialchars($_POST['password']);
  9.            
  10.             $stmt = $db->prepare('SELECT * FROM users WHERE username = :username');
  11.             $stmt->bindParam(':username',$username);
  12.             $stmt->execute();
  13.             $user = $stmt->fetch();
  14.             if($user != null)
  15.             {
  16.                 if(password_verify($password,$user['password'])){
  17.                     $_SESSION['login']=$user['id'];
  18.                     header('Location: dashboard.php');
  19.                 }else{
  20.                     $_SESSION['error'] = 'Mot de passe incorrect !';
  21.                 }
  22.             }else{
  23.                 $_SESSION['error'] = 'L\'utilisateur n\'existe pas';
  24.             }
  25.         }
  26.     }
  27. ?>
  28. <h2>Connexion</h2>
  29. <?php
  30.     if(isset($_SESSION['error'])){
  31.         echo $_SESSION['error'];
  32.         unset($_SESSION['error']);
  33.     }
  34. ?>
  35. <form method="post">
  36. <label>Nom d'utilisateur : <input type="text" name="username"></label>
  37. <label>Mot de passe : <input type="password" name="password"></label>
  38. <button type="submit" name="submit">Se connecter</button>
  39. </form>
  40. <?php
  41.     require_once('resources/template/bottom.php');
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement