Advertisement
Guest User

Untitled

a guest
Feb 13th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. if ($type == 'login')
  2. {
  3.  
  4. echo 's';
  5. $username = $_POST['username'];
  6. $password = $_POST['password'];
  7. $date = strtotime('-1 hour', time());
  8. $attempts=$odb->query("SELECT COUNT(*) FROM `loginlogs` WHERE `ip` = '$ip' AND `username` LIKE '%failed' AND `date` BETWEEN '$date' AND CURRENT_TIMESTAMP()")->fetchColumn(0);
  9. if ($attempts>2) {
  10. $date = strtotime('+1 hour', $waittime=$odb->query("SELECT `date` FROM `loginlogs` WHERE `ip` = '$ip' ORDER BY `date` DESC LIMIT 1")->fetchColumn(0) - time());
  11. die(error('Too many failed attempts. Please wait '.$date.' seconds and try again.'));
  12. }
  13.  
  14. //Check fields
  15. if (empty($username) || empty($password) || !ctype_alnum($username) || strlen($username) < 4 || strlen($username) > 15)
  16. {
  17. die(error('Please fill in all fields.'));
  18. }
  19.  
  20. //Check login details
  21. $SQLCheckLogin = $odb -> prepare("SELECT COUNT(*) FROM `users` WHERE `username` = :username AND `password` = :password");
  22. $SQLCheckLogin -> execute(array(':username' => $username, ':password' => SHA1(md5($password))));
  23. $countLogin = $SQLCheckLogin -> fetchColumn(0);
  24. if (!($countLogin == 1))
  25. {
  26. $SQL = $odb -> prepare("INSERT INTO `loginlogs` VALUES(:username, :ip, CURRENT_TIMESTAMP, 'XX')");
  27. $SQL -> execute(array(':username' => $username,':ip' => $ip));
  28. die(error('Username or password are invalid.'));
  29. }
  30.  
  31. //Check if the user is banned
  32. $SQL = $odb -> prepare("SELECT `status` FROM `users` WHERE `username` = :username");
  33. $SQL -> execute(array(':username' => $username));
  34. $status = $SQL -> fetchColumn(0);
  35. if ($status == 1)
  36. {
  37. $ban = $odb -> query("SELECT `reason` FROM `bans` WHERE `username` = '$username'") -> fetchColumn(0);
  38. die(error('You are banned. Reason: '.htmlspecialchars($ban)));
  39. }
  40.  
  41. //Insert login log and log in
  42. $SQL = $odb -> prepare("SELECT * FROM `users` WHERE `username` = :username");
  43. $SQL -> execute(array(':username' => $username));
  44. $userInfo = $SQL -> fetch();
  45. $ipcountry = json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip)) -> {'geoplugin_countryName'};
  46. if (empty($ipcountry)) {$ipcountry = 'XX';}
  47. $SQL = $odb -> prepare('INSERT INTO `loginlogs` VALUES(:username, :ip, CURRENT_TIMESTAMP, :ipcountry)');
  48. $SQL -> execute(array(':ip' => $ip, ':username' => $username, ':ipcountry' => $ipcountry));
  49. $_SESSION['username'] = $userInfo['username'];
  50. $_SESSION['ID'] = $userInfo['ID'];
  51. echo success(' Login Successful. Redirecting...<meta http-equiv="refresh" content="3;URL=index.php">');
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement