Guest User

Untitled

a guest
Apr 29th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. <?php
  2. function check(PDO $muc){
  3. function get_multiple_rows($getfailed) {
  4. $rows = array();
  5. while($row = $getfailed->fetch(PDO::FETCH_ASSOC)) {
  6. $rows[] = $row;
  7. }
  8. return $rows;
  9. }
  10. $throttle = array(1 => 1, 5 => 2, 30 => 10);
  11. if ($getfailed = $muc->query("SELECT MAX(attempted) AS attempted FROM failed_logins")){
  12. $rows = get_multiple_rows($getfailed);
  13. $getfailed->closeCursor();
  14. $latest_attempt = (int) date('U', strtotime($rows[0]['attempted']));
  15. if ($getfailed = $muc->query("SELECT COUNT(1) AS failed FROM failed_logins WHERE attempted > DATE_SUB(NOW(), INTERVAL 15 minute)")){
  16. $rows = get_multiple_rows($getfailed);
  17. $getfailed->closeCursor();
  18. $failed_attempts = (int) $rows[0]['failed'];
  19. krsort($throttle);
  20. foreach ($throttle as $attempts => $delay){
  21. if ($failed_attempts > $attempts) {
  22. $remaining_delay = (time() - $latest_attempt) - $delay;
  23. if ($remaining_delay < 0){
  24. echo "remaining time until next try".abs($remaining_delay);
  25. }
  26. return false;
  27. break;
  28. }else{
  29. return true;
  30. }
  31. }
  32. }
  33. }
  34. }
  35. ?>
  36.  
  37. <?php
  38. if(check($muc) === true){
  39. $much = $muc->query('SELECT * from users_enc WHERE name=name');
  40. $much->bindParam(1, $name);
  41. $much->bindParam(2, $password);
  42. $much->execute();
  43. $much->setFetchMode(PDO::FETCH_ASSOC);
  44. while($row = $much->fetch()) {
  45. $dbname = $row['Name'];
  46. $dbpassword = $row['Password'];
  47. }
  48. if($_POST['name']==$dbname){
  49. if (password_verify($_POST['password'], $dbpassword)){
  50. session_start();
  51. $_SESSION['Name'] = $_POST['name'];
  52. $_SESSION['Password'] = $_POST['password'];
  53. $successq = $muc->query("DELETE FROM failed_logins WHERE name = '".$_SESSION['Name']."'");
  54. $successq->execute();
  55. echo"<a href='../onlinestore.php' style='color:green;padding:10px;background-color:rgba(240,255,240,0.5);border:1px solid green;border-radius:5px;'>You can enter here</a><br /><br />";
  56. }else{
  57. echo $err4;
  58. include("throttle.php");
  59. }
  60. }else{
  61. echo $err3;
  62. include("throttle.php");
  63. $stmt = $muc->prepare('SELECT Name from failed_logins WHERE name=:name');
  64. $stmt->bindParam(':name', $name);
  65. $stmt->execute();
  66. if($stmt->rowCount() > 200){
  67. $overdose = $muc->query("DELETE FROM failed_logins WHERE name = '".$_SESSION['Name']."'");
  68. $overdose->execute();
  69. }
  70. }
  71. }
  72. ?>
Add Comment
Please, Sign In to add comment