Advertisement
Guest User

Untitled

a guest
Feb 10th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. <?php
  2. if (!($user -> LoggedIn()))
  3. {
  4. if (isset($_POST['doLogin']))
  5. {
  6. $username = $_POST['login-username'];
  7. $password = $_POST['login-password'];
  8. $errors = array();
  9.  
  10.  
  11. if (empty($username) || empty($password))
  12. {
  13. $errors[] = 'Пожалуйста, введите имя пользователя и пароль.';
  14. }
  15. if (!ctype_alnum($username) || strlen($username) < 4 || strlen($username) > 15)
  16. {
  17. $errors[] = ' Имя пользователя должно быть не более 4-15 символов и только буквенно-цифровое.';
  18. }
  19.  
  20. if (empty($errors))
  21. {
  22. $SQLCheckLogin = $odb -> prepare("SELECT COUNT(*) FROM `users` WHERE `username` = :username");
  23. $SQLCheckLogin -> execute(array(':username' => $username));
  24. $countLogin = $SQLCheckLogin -> fetchColumn(0);
  25. if ($countLogin == 1)
  26. {
  27. $gethashSQL = $odb -> prepare("SELECT `password` FROM `users` WHERE `username` = :username");
  28. $gethashSQL -> execute(array(":username" => $username));
  29. $hash = $gethashSQL -> fetch();
  30.  
  31. if (hash_equals($hash['password'], crypt($password, $hash['password'])))
  32. {
  33. $SQLGetInfo = $odb -> prepare("SELECT `username`, `ID`, `membership`, `status` FROM `users` WHERE `username` = :username");
  34. $SQLGetInfo -> execute(array(':username' => $username));
  35. $userInfo = $SQLGetInfo -> fetch(PDO::FETCH_ASSOC);
  36. $status = $userInfo['status'];
  37. $userid = $userInfo['ID'];
  38. $userip = $_SERVER['REMOTE_ADDR'];
  39. $ban = $odb -> query("SELECT `reason` FROM `bans` WHERE `username` = '$username'") -> fetchColumn(0);
  40. if(empty($ban))
  41. {
  42. $ban = "Причина отсутствует.";
  43. }
  44. if ($status == 0)
  45. {
  46. $username = $userInfo['username'];
  47. $_SESSION['username'] = $userInfo['username'];
  48. $_SESSION['ID'] = $userInfo['ID'];
  49.  
  50. $ipcountry = json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip)) -> {'geoplugin_countryName'};
  51. if (empty($ipcountry)) {$ipcountry = 'XX';}
  52. $SQL = $odb -> prepare('INSERT INTO `loginlogs` VALUES(NULL, :username, :ip, UNIX_TIMESTAMP(), :ipcountry)');
  53. $SQL -> execute(array(':ip' => $ip, ':username' => $username, ':ipcountry' => $ipcountry));
  54.  
  55. setcookie("username", $userInfo['username'], time() + 720000);
  56. header('Location: home.php');
  57. setSessionPackage($userInfo['membership']);
  58. exit;
  59.  
  60.  
  61. echo '<div class="alert alert-success"><p><center>Авторизация успешна! Перенаправление...</center></p></div>';
  62. }
  63. else
  64. {
  65. echo ('<div class="alert alert-danger"><p><center>Ваша учётная запись заблокирована!</br>Причина: ' . htmlspecialchars($ban) . ' </center></p></div>' .htmlspecialchars($ban));
  66. }
  67. }
  68. else
  69. {
  70. echo '<div class="alert alert-danger"><p><center>Неверный пароль.</center></p></div>';
  71. }
  72. }
  73. else
  74. {
  75. echo '<div class="alert alert-danger"><p><center>Такого пользователя не существует.</center></p></div>';
  76. }
  77. }
  78. else
  79. {
  80. echo '<center><div class="alert alert-danger"><p><strong></strong>';
  81. foreach($errors as $error)
  82. {
  83. echo ''.$error.'';
  84. }
  85. echo '</div></center>';
  86. }
  87. }
  88. }
  89. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement