Advertisement
Guest User

Untitled

a guest
Mar 9th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace UserLogins
  5. {
  6. class UserLogins
  7. {
  8. public static void Main()
  9. {
  10. var input = Console.ReadLine();
  11. var result = new Dictionary<string, string>();
  12. int logginsFailed = 0;
  13. bool loginStarted = false;
  14.  
  15. while (input != "end")
  16. {
  17. var tokens = input.Split(new char[] { '-', '>', ' ' }, StringSplitOptions.RemoveEmptyEntries);
  18. var username = tokens[0];
  19. string password;
  20.  
  21. if (tokens.Length == 1)
  22. {
  23. password = null;
  24. }
  25. else
  26. {
  27. password = tokens[1];
  28. }
  29.  
  30. if (input == "login")
  31. {
  32. loginStarted = true;
  33. }
  34.  
  35. if (!result.ContainsKey(username) && loginStarted == false)
  36. {
  37. result[username] = password;
  38. }
  39. else if (result.ContainsKey(username) && loginStarted == false)
  40. {
  41. result[username] = password;
  42. }
  43. else if (loginStarted == true && ((result.ContainsKey(username) && !result.ContainsValue(password)) || (!result.ContainsKey(username) && result.ContainsValue(password))))
  44. {
  45. Console.WriteLine($"{username}: login failed");
  46. logginsFailed++;
  47. }
  48. else if (input != "login")
  49. {
  50. Console.WriteLine($"{username}: logged in successfully");
  51. }
  52.  
  53. input = Console.ReadLine();
  54. }
  55. Console.WriteLine($"unsuccessful login attempts: {logginsFailed}");
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement