Advertisement
Guest User

Untitled

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