Advertisement
Guest User

User Logins 100%

a guest
Jul 7th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _05.User_Logins
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<string> inputUserNameAndPass = Console.ReadLine()
  14.                 .Split(new char[] { ' ', '-', '>' })
  15.                 .ToList();
  16.                        
  17.  
  18.             Dictionary<string, string> usernameAndPass = new Dictionary<string, string>();
  19.            
  20.  
  21.             while (inputUserNameAndPass[0] != "login")
  22.             {
  23.                 string username = inputUserNameAndPass[0];
  24.                 string password = inputUserNameAndPass[4];
  25.  
  26.                 usernameAndPass[username] = password;
  27.  
  28.                 inputUserNameAndPass = Console.ReadLine()
  29.                 .Split(new char[] { ' ', '-', '>' })
  30.                 .ToList();
  31.             }
  32.             inputUserNameAndPass = Console.ReadLine()
  33.                 .Split(new char[] { ' ', '-', '>' })
  34.                 .ToList();
  35.  
  36.             int countUnsuccessfulLogin = 0;
  37.  
  38.             while (inputUserNameAndPass[0] != "end")
  39.             {
  40.                 string username = inputUserNameAndPass[0];
  41.                 string password = inputUserNameAndPass[4];
  42.  
  43.                 if (usernameAndPass.ContainsKey(username) && usernameAndPass.ContainsValue(password))
  44.                 {
  45.                     Console.WriteLine($"{username}: logged in successfully ");
  46.                 }
  47.                 else if (!usernameAndPass.ContainsKey(username) || usernameAndPass[username] != password)
  48.                 {
  49.                     Console.WriteLine($"{username}: login failed");
  50.                     countUnsuccessfulLogin++;
  51.  
  52.                 }
  53.  
  54.  
  55.                 inputUserNameAndPass = Console.ReadLine()
  56.                 .Split(new char[] { ' ', '-', '>' })
  57.                 .ToList();
  58.             }
  59.  
  60.            
  61.             Console.WriteLine($"unsuccessful login attempts: {countUnsuccessfulLogin}");
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement