Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = trim(fgets(STDIN));
- $usernamePasswordPPairs = [];
- while (1) {
- if ($input == 'login'){
- break;
- }
- $currInput = explode('->',$input);
- $user = trim($currInput[0]);
- $pass = trim($currInput[1]);
- $usernamePasswordPPairs[$user] = $pass;
- $input = trim(fgets(STDIN));
- }
- $loginRequestInput = trim(fgets(STDIN));
- $unsuccessfulLogin = 0;
- while (1) {
- if ($loginRequestInput == 'end'){
- break;
- }
- $currLoginRequestInput = explode('->',$loginRequestInput);
- $userLog = trim($currLoginRequestInput[0]);
- $passLog = trim($currLoginRequestInput[1]);
- $login = false;
- foreach ($usernamePasswordPPairs as $userName => $password) {
- if (($userName == $userLog) && ($password == $passLog)){
- print "$userLog: logged in successfully \r\n";
- $login = true;
- }
- }
- if (!$login){
- print "$userLog: login failed \r\n";
- $unsuccessfulLogin ++;
- }
- $loginRequestInput = trim(fgets(STDIN));
- }
- print "unsuccessful login attempt: $unsuccessfulLogin";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement