Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. <?php
  2.  
  3. if (!($user -> LoggedIn()))
  4. {
  5. if (isset($_POST['loginBtn']))
  6. {
  7. $username = $_POST['username'];
  8. $password = $_POST['password'];
  9. $errors = array();
  10. if (!ctype_alnum($username) || strlen($username) < 4 || strlen($username) > 15)
  11. {
  12. //$errors[] = 'Username Must Be Alphanumberic And 4-15 characters in length';
  13. }
  14.  
  15. if (empty($username) || empty($password))
  16. {
  17. $errors[] = 'Please fill in all fields';
  18. }
  19.  
  20. if (empty($errors))
  21. {
  22. $SQLCheckLogin = $odb -> prepare("SELECT COUNT(*) FROM `users` WHERE `username` = :username AND `password` = :password");
  23. $SQLCheckLogin -> execute(array(':username' => $username, ':password' => SHA1($password)));
  24. $countLogin = $SQLCheckLogin -> fetchColumn(0);
  25. if ($countLogin == 1)
  26. {
  27. $SQLGetInfo = $odb -> prepare("SELECT `username`, `ID`, `status` FROM `users` WHERE `username` = :username AND `password` = :password");
  28. $SQLGetInfo -> execute(array(':username' => $username, ':password' => SHA1($password)));
  29. $userInfo = $SQLGetInfo -> fetch(PDO::FETCH_ASSOC);
  30. if ($userInfo['status'] == 0)
  31. {
  32. $logAddr = $odb->prepare("INSERT INTO `login_history` (`username`,`ip`,`date`,`http_agent`) VALUES (:user, :ip, UNIX_TIMESTAMP(NOW()), :agent);");
  33. $logAddr->execute(array( ":user" => $username, ":ip" => $_SERVER['REMOTE_ADDR'], ":agent" => $_SERVER['HTTP_USER_AGENT']));
  34. $_SESSION['username'] = $userInfo['username'];
  35. $_SESSION['email'] = $userInfo['email'];
  36. $_SESSION['ID'] = $userInfo['ID'];
  37. echo '<script>swal("Success!", "You will get redirected!", "success")</script><meta http-equiv="refresh" content="1;url=index.php">';
  38. }
  39. else
  40. {
  41. echo '<script>swal("ERROR!", "Your account has been suspended!", "error")</script>';
  42. }
  43. }
  44. else
  45. {
  46. echo '<script>swal("ERROR!", "Login Failed!", "error")</script>';
  47. }
  48. }
  49. else
  50. {
  51. echo '<script>swal("ERROR!", ';
  52. foreach($errors as $error)
  53. {
  54. echo '"'.$error.'"';
  55. }
  56. echo ', "error")</script>';
  57. }
  58. }
  59. }
  60. else
  61. {
  62. header('location: index.php');
  63. }
  64. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement