Advertisement
Guest User

Untitled

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