Advertisement
Guest User

Untitled

a guest
Oct 9th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.31 KB | None | 0 0
  1. <?php
  2. $page = "Login";
  3. include('assets/includes/global.php');
  4. include('assets/includes/header.php');
  5.  
  6. $message = "";
  7.  
  8. if (isset($_POST['username'])) {
  9.     $user = $_POST['username'];
  10.     $pass = $_POST['password'];
  11.    
  12.     if ((!$user) || (!$pass)) {
  13.         $message = "Please complete all fields";
  14.     } else {
  15.         $passCrypt = crypt($pass);
  16.         $stmt = $mysqli->prepare("SELECT `id`, `password` FROM `users` WHERE `username` = ? LIMIT 1");
  17.         $stmt->bind_param('s', $user);
  18.         $stmt->execute();
  19.         $stmt->bind_result($id, $pwhash);
  20.         if ($stmt->fetch()) {
  21.             $stmt->close();
  22.             if ($pwhash !== crypt($passCyrpt, $pwhash)) {
  23.                 $message = "Invalid Credentials";
  24.             } else {
  25.                 $_SESSION['password'] = $pwhash;
  26.                 $_SESSION['username'] = $user;
  27.                 $_SESSION['id'] = $id;
  28.                
  29.                 header("Location: ./");
  30.                
  31.                 $message = "Session started, you are logged in.";
  32.             }
  33.         } else {
  34.             $message = "Invalid Credentials";
  35.         }
  36.     }
  37. }
  38.  
  39. ?>
  40.  
  41. <div id="bodyWrapper">
  42.     <div class="global-form" id="registerform">
  43.         <div class="container">
  44.             <div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">
  45.                 <form action="login.php" method="POST" role="form" autocomplete="off">
  46.                     <img src="https://elcrodevelopment.com/checkout/assets/imgs/logo.png" alt="Logo" width="250" style="padding-bottom: 10px;text-align:center;">
  47.                     <p class="form-intro" style="font-size:22px;color:#000;">Login to your Dashboard</p>
  48.                     <p style="color:#000;"><?= $message ?></p>
  49.                     <fieldset class="form-group">
  50.                         <input type="text" class="form-control" name="username" placeholder="Username" required>
  51.                     </fieldset>
  52.                     <fieldset class="form-group">
  53.                         <input type="password" class="form-control" name="password" placeholder="Password" required>
  54.                     </fieldset>
  55.                     <div id="button">
  56.                         <p style="text-align: center;padding-bottom:2px;">Don't have an account? <a href="register.php">Register</a></p>
  57.                         <button type="submit" id="clientbutton2" class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3 btn btn-primary">Login</button>
  58.                     </div>
  59.                 </form>
  60.             </div>
  61.         </div>
  62.     </div>
  63. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement