Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. <?php
  2. $input = trim(fgets(STDIN));
  3.  
  4. $usernamePasswordPPairs = [];
  5. while (1) {
  6. if ($input == 'login'){
  7. break;
  8. }
  9. $currInput = explode('->',$input);
  10.  
  11. $user = trim($currInput[0]);
  12. $pass = trim($currInput[1]);
  13.  
  14. $usernamePasswordPPairs[$user] = $pass;
  15.  
  16. $input = trim(fgets(STDIN));
  17. }
  18.  
  19. $loginRequestInput = trim(fgets(STDIN));
  20. $unsuccessfulLogin = 0;
  21.  
  22. while (1) {
  23. if ($loginRequestInput == 'end'){
  24. break;
  25. }
  26. $currLoginRequestInput = explode('->',$loginRequestInput);
  27.  
  28. $userLog = trim($currLoginRequestInput[0]);
  29. $passLog = trim($currLoginRequestInput[1]);
  30.  
  31. $login = false;
  32.  
  33. foreach ($usernamePasswordPPairs as $userName => $password) {
  34. if (($userName == $userLog) && ($password == $passLog)){
  35. print "$userLog: logged in successfully \r\n";
  36. $login = true;
  37. }
  38. }
  39.  
  40. if (!$login){
  41. print "$userLog: login failed \r\n";
  42. $unsuccessfulLogin ++;
  43. }
  44.  
  45. $loginRequestInput = trim(fgets(STDIN));
  46. }
  47.  
  48. print "unsuccessful login attempt: $unsuccessfulLogin";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement