Advertisement
ItsWidee

Untitled

Feb 19th, 2021
911
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.11 KB | None | 0 0
  1.  
  2. <?php
  3. require_once 'includes/needed.php';
  4. require_once 'includes/db.php';
  5. require_once 'includes/functions.php';
  6.  
  7. if(isset($_SESSION['auth'])){
  8.     header('Location: account.php');
  9. }
  10.  
  11. if(!empty($_POST['pseudo']) && !empty($_POST['mdp'])){
  12.     require_once 'includes/db.php';
  13.     $req = $pdo->prepare('SELECT * FROM users WHERE (username = :username OR email = :username) AND (confirmed_at IS NOT NULL AND is_confirmed = 1)');
  14.     $req->execute(['username' => $_POST['pseudo']]);
  15.     $user = $req->fetch();
  16.     if($user){
  17.         if(password_verify($_POST['mdp'], $user['password'])){
  18.             if($_POST['remember']){
  19.                 $remember_token = str_random(250);
  20.                 $pdo->prepare('UPDATE users SET remember_token = ? WHERE id = ?')->execute([$remember_token, $user['id']]);
  21.                 setcookie('remember', $user['id'] . '==' . $remember_token . sha1($user['id'] . 'ratonlaveurs'), time() + 60 * 60 * 24 * 7);
  22.                 $_SESSION['auth'] = $user;
  23.                 $_SESSION['flash']['success'] = 'Vous êtes désormais connecté à StoryShare';
  24.                 header('Location: account.php');
  25.             } else {
  26.                 $_SESSION['auth'] = $user;
  27.                 $_SESSION['flash']['success'] = 'Vous êtes désormais connecté à StoryShare';
  28.                 header('Location: account.php');
  29.             }
  30.         } else {
  31.             $_SESSION['flash']['danger'] = "Identifiant ou mot de passe incorrect";
  32.         }
  33.     } else {
  34.         $_SESSION['flash']['danger'] = "Identifiant ou mot de passe incorrect";
  35.     }
  36. }
  37. ?>
  38.  
  39. <!DOCTYPE html>
  40. <html>
  41. <head>
  42.     <meta charset="UTF-8">
  43.     <link rel="stylesheet" type="text/css" href="styles/style.css">
  44.     <link rel="shortcut icon" type="image/png" href="ressources/images/logo-small-final.png"/>
  45.     <link rel="stylesheet" type="text/css" href="styles/style_connexion.css">
  46.     <title>Connexion | StoryShare</title>
  47. </head>
  48. <body>
  49. <div id="bloc-page">
  50.     <?php require 'includes/header.php'; ?>
  51.    
  52.         <div id="page">
  53.             <h1 id="form_title">Connexion</h1>
  54.             <div id="connexion_page">
  55.                 <form method="post" action="">
  56.                 <div>
  57.                 <label for="pseudo">Pseudonyme ou email :</label>
  58.                 <input type="text" name="pseudo" id="pseudo" placeholder="Pseudonyme" required>
  59.                 </div>
  60.                 <div>
  61.                 <label for="mdp">Mot de passe :</label>
  62.                 <input type="password" name="mdp" id="mdp" minlength="8" maxlength="255" placeholder="Mot de passe" required>
  63.                 </div>
  64.                 <div>
  65.                 <label><input type="checkbox" name="remember" id="remember" value="0"/> Se souvenir de moi</label>
  66.                 </div>
  67.                 <div>
  68.                 <input type="submit" name="formconnexion" value="Se connecter">
  69.                 </div>
  70.                 <p>
  71.                 <a href="forget.php" id="except-link">Mot de passe oublié ?</a>
  72.                 </p>
  73.                 </form>
  74.             </div>
  75.     </div>
  76.     <?php require 'includes/footer.php'; ?>
  77. </div>
  78. </body>
  79. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement