Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'includes/needed.php';
- require_once 'includes/db.php';
- require_once 'includes/functions.php';
- if(isset($_SESSION['auth'])){
- header('Location: account.php');
- }
- if(!empty($_POST['pseudo']) && !empty($_POST['mdp'])){
- require_once 'includes/db.php';
- $req = $pdo->prepare('SELECT * FROM users WHERE (username = :username OR email = :username) AND (confirmed_at IS NOT NULL AND is_confirmed = 1)');
- $req->execute(['username' => $_POST['pseudo']]);
- $user = $req->fetch();
- if($user){
- if(password_verify($_POST['mdp'], $user['password'])){
- if($_POST['remember']){
- $remember_token = str_random(250);
- $pdo->prepare('UPDATE users SET remember_token = ? WHERE id = ?')->execute([$remember_token, $user['id']]);
- setcookie('remember', $user['id'] . '==' . $remember_token . sha1($user['id'] . 'ratonlaveurs'), time() + 60 * 60 * 24 * 7);
- $_SESSION['auth'] = $user;
- $_SESSION['flash']['success'] = 'Vous êtes désormais connecté à StoryShare';
- header('Location: account.php');
- } else {
- $_SESSION['auth'] = $user;
- $_SESSION['flash']['success'] = 'Vous êtes désormais connecté à StoryShare';
- header('Location: account.php');
- }
- } else {
- $_SESSION['flash']['danger'] = "Identifiant ou mot de passe incorrect";
- }
- } else {
- $_SESSION['flash']['danger'] = "Identifiant ou mot de passe incorrect";
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <link rel="stylesheet" type="text/css" href="styles/style.css">
- <link rel="shortcut icon" type="image/png" href="ressources/images/logo-small-final.png"/>
- <link rel="stylesheet" type="text/css" href="styles/style_connexion.css">
- <title>Connexion | StoryShare</title>
- </head>
- <body>
- <div id="bloc-page">
- <?php require 'includes/header.php'; ?>
- <div id="page">
- <h1 id="form_title">Connexion</h1>
- <div id="connexion_page">
- <form method="post" action="">
- <div>
- <label for="pseudo">Pseudonyme ou email :</label>
- <input type="text" name="pseudo" id="pseudo" placeholder="Pseudonyme" required>
- </div>
- <div>
- <label for="mdp">Mot de passe :</label>
- <input type="password" name="mdp" id="mdp" minlength="8" maxlength="255" placeholder="Mot de passe" required>
- </div>
- <div>
- <label><input type="checkbox" name="remember" id="remember" value="0"/> Se souvenir de moi</label>
- </div>
- <div>
- <input type="submit" name="formconnexion" value="Se connecter">
- </div>
- <p>
- <a href="forget.php" id="except-link">Mot de passe oublié ?</a>
- </p>
- </form>
- </div>
- </div>
- <?php require 'includes/footer.php'; ?>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement