Advertisement
Guest User

Untitled

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