Guest User

Untitled

a guest
Jan 24th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.80 KB | None | 0 0
  1. <?php
  2. //login.php
  3.  
  4. /**
  5. * Start the session.
  6. */
  7. session_start();
  8.  
  9. /**
  10. * Include ircmaxell's password_compat library.
  11. */
  12. require 'lib/password.php';
  13.  
  14. /**
  15. * Include our MySQL connection.
  16. */
  17. require 'connect.php';
  18.  
  19.  
  20. //If the POST var "login" exists (our submit button), then we can
  21. //assume that the user has submitted the login form.
  22. if(isset($_POST['login'])){
  23.  
  24. //Retrieve the field values from our login form.
  25. $username = !empty($_POST['username']) ? trim($_POST['username']) : null;
  26. $passwordAttempt = !empty($_POST['password']) ? trim($_POST['password']) : null;
  27.  
  28. //Retrieve the user account information for the given username.
  29. $sql = "SELECT id, username, password FROM users WHERE username = :username";
  30. $stmt = $pdo->prepare($sql);
  31.  
  32. //Bind value.
  33. $stmt->bindValue(':username', $username);
  34.  
  35. //Execute.
  36. $stmt->execute();
  37.  
  38. //Fetch row.
  39. $user = $stmt->fetch(PDO::FETCH_ASSOC);
  40.  
  41. //If $row is FALSE.
  42. if($user === false){
  43. //Could not find a user with that username!
  44. //PS: You might want to handle this error in a more user-friendly manner!
  45. die('Incorrect username / password combination!');
  46. } else{
  47. //User account found. Check to see if the given password matches the
  48. //password hash that we stored in our users table.
  49.  
  50. //Compare the passwords.
  51. $validPassword = password_verify($passwordAttempt, $user['password']);
  52.  
  53. //If $validPassword is TRUE, the login has been successful.
  54. if($validPassword){
  55.  
  56. //Provide the user with a login session.
  57. $_SESSION['user_id'] = $user['id'];
  58. $_SESSION['logged_in'] = time();
  59.  
  60. //Redirect to our protected page, which we called home.php
  61. header('Location: home.php');
  62. exit;
  63.  
  64. } else{
  65. //$validPassword was FALSE. Passwords do not match.
  66. die('Incorrect username / password combination!');
  67. }
  68. }
  69.  
  70. }
  71.  
  72. ?>
  73.  
  74. <!DOCTYPE html>
  75. <html lang="en">
  76. <head>
  77. <title>Login V20</title>
  78. <meta charset="UTF-8">
  79. <meta name="viewport" content="width=device-width, initial-scale=1">
  80. <!--===============================================================================================-->
  81. <link rel="icon" type="image/png" href="images/icons/favicon.ico"/>
  82. <!--===============================================================================================-->
  83. <link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">
  84. <!--===============================================================================================-->
  85. <link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.7.0/css/font-awesome.min.css">
  86. <!--===============================================================================================-->
  87. <link rel="stylesheet" type="text/css" href="fonts/Linearicons-Free-v1.0.0/icon-font.min.css">
  88. <!--===============================================================================================-->
  89. <link rel="stylesheet" type="text/css" href="vendor/animate/animate.css">
  90. <!--===============================================================================================-->
  91. <link rel="stylesheet" type="text/css" href="vendor/css-hamburgers/hamburgers.min.css">
  92. <!--===============================================================================================-->
  93. <link rel="stylesheet" type="text/css" href="vendor/animsition/css/animsition.min.css">
  94. <!--===============================================================================================-->
  95. <link rel="stylesheet" type="text/css" href="vendor/select2/select2.min.css">
  96. <!--===============================================================================================-->
  97. <link rel="stylesheet" type="text/css" href="vendor/daterangepicker/daterangepicker.css">
  98. <!--===============================================================================================-->
  99. <link rel="stylesheet" type="text/css" href="css/util.css">
  100. <link rel="stylesheet" type="text/css" href="css/main.css">
  101. <!--===============================================================================================-->
  102. </head>
  103. <body>
  104.  
  105. <div class="limiter">
  106. <div class="container-login100">
  107. <div class="wrap-login100 p-b-160 p-t-50">
  108. <form class="login100-form validate-form">
  109. <span class="login100-form-title p-b-43">
  110. Account Login
  111. </span>
  112.  
  113. <div class="wrap-input100 rs1 validate-input" data-validate = "Username is required">
  114. <input class="input100" type="text" name="username">
  115. <span class="label-input100">Username</span>
  116. </div>
  117.  
  118.  
  119. <div class="wrap-input100 rs2 validate-input" data-validate="Password is required">
  120. <input class="input100" type="password" name="pass">
  121. <span class="label-input100">Password</span>
  122. </div>
  123.  
  124. <div class="container-login100-form-btn">
  125. <button class="login100-form-btn" type ="submit" name="login" value="Login" >
  126. Sign in
  127. </button>
  128. </div>
  129.  
  130. <div class="text-center w-full p-t-23">
  131. <a href="#" class="txt1">
  132. Forgot password?
  133. </a>
  134. </div>
  135. </form>
  136. </div>
  137. </div>
  138. </div>
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145. <!--===============================================================================================-->
  146. <script src="vendor/jquery/jquery-3.2.1.min.js"></script>
  147. <!--===============================================================================================-->
  148. <script src="vendor/animsition/js/animsition.min.js"></script>
  149. <!--===============================================================================================-->
  150. <script src="vendor/bootstrap/js/popper.js"></script>
  151. <script src="vendor/bootstrap/js/bootstrap.min.js"></script>
  152. <!--===============================================================================================-->
  153. <script src="vendor/select2/select2.min.js"></script>
  154. <!--===============================================================================================-->
  155. <script src="vendor/daterangepicker/moment.min.js"></script>
  156. <script src="vendor/daterangepicker/daterangepicker.js"></script>
  157. <!--===============================================================================================-->
  158. <script src="vendor/countdowntime/countdowntime.js"></script>
  159. <!--===============================================================================================-->
  160. <script src="js/main.js"></script>
  161.  
  162. </body>
  163. </html>
Add Comment
Please, Sign In to add comment