Advertisement
Guest User

milw0rm

a guest
Apr 7th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5. if (!($user -> LoggedIn()))
  6.  
  7. {
  8.  
  9. if (isset($_POST['loginBtn']))
  10.  
  11. {
  12.  
  13. $username = $_POST['username'];
  14.  
  15. $password = $_POST['password'];
  16.  
  17. $errors = array();
  18.  
  19. if (!ctype_alnum($username) || strlen($username) < 4 || strlen($username) > 15)
  20.  
  21. {
  22.  
  23. $errors[] = 'Username must be 4-15 characters in length';
  24.  
  25. }
  26.  
  27.  
  28.  
  29. if (empty($username) || empty($password))
  30.  
  31. {
  32.  
  33. $errors[] = 'Please fill in all fields';
  34.  
  35. }
  36.  
  37.  
  38.  
  39. if (empty($errors))
  40.  
  41. {
  42.  
  43. $SQLCheckLogin = $odb -> prepare("SELECT COUNT(*) FROM `users` WHERE `username` = :username");
  44.  
  45. $SQLCheckLogin -> execute(array(':username' => $username));
  46.  
  47. $countLogin = $SQLCheckLogin -> fetchColumn(0);
  48.  
  49. if ($countLogin == 1)
  50.  
  51. {
  52.  
  53.  
  54.  
  55. $gethashSQL = $odb -> prepare("SELECT `password` FROM `users` WHERE `username` = :username");
  56.  
  57. $gethashSQL -> execute(array(":username" => $username));
  58.  
  59. $hash = $gethashSQL -> fetch();
  60.  
  61.  
  62.  
  63. if (hash_equals($hash['password'], crypt($password, $hash['password']))) {
  64.  
  65.  
  66.  
  67. $SQLGetInfo = $odb -> prepare("SELECT `username`, `ID` FROM `users` WHERE `username` = :username");
  68.  
  69. $SQLGetInfo -> execute(array(':username' => $username));
  70.  
  71. $userInfo = $SQLGetInfo -> fetch(PDO::FETCH_ASSOC);
  72.  
  73. if ($userInfo['status'] == 0)
  74.  
  75. {
  76. $username = $userInfo['username'];
  77. $_SESSION['username'] = $userInfo['username'];
  78.  
  79. $_SESSION['ID'] = $userInfo['ID'];
  80.  
  81.  
  82.  
  83. echo '<div class="alert alert-success alert-dismissable fade in"><p><center>Login Successful! Redirecting...</center></p></div><meta http-equiv="refresh" content="3;url=dashboard.php">';
  84.  
  85. }
  86.  
  87. else
  88.  
  89. {
  90.  
  91. echo '<div class="alert alert-danger alert-dismissable fade in"><p><center>You have been banned!</center></p></div>';
  92.  
  93. }
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101. } else {
  102.  
  103. echo '<div class="alert alert-danger alert-dismissable fade in"><p><center>Login Failed! Please try again.</center></p></div>';
  104.  
  105. }
  106.  
  107.  
  108.  
  109. }
  110.  
  111. else
  112.  
  113. {
  114.  
  115. echo '<div class="alert alert-danger alert-dismissable fade in"><p><center>Login Failed! Please try again.</center></p></div>';
  116.  
  117. }
  118.  
  119. }
  120.  
  121. else
  122.  
  123. {
  124.  
  125. echo '<center><div class="alert alert-danger alert-dismissable fade in"><p><strong></strong>';
  126.  
  127. foreach($errors as $error)
  128.  
  129. {
  130.  
  131. echo ''.$error.'';
  132.  
  133. }
  134.  
  135. echo '</div></center>';
  136.  
  137. }
  138.  
  139. }
  140.  
  141. }
  142.  
  143. else
  144.  
  145. {
  146.  
  147. header('location: dashboard.php');
  148.  
  149. }
  150.  
  151. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement