Advertisement
KirillKorobka

Untitled

Nov 28th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Kirill_1
  4. {
  5. class Program
  6. {
  7.  
  8. static int[] CountCharacterTypes(string pass)
  9. {
  10. int[] res = new int[4];
  11.  
  12. foreach (var ch in pass)
  13. {
  14. if (ch >= '0' && ch <= '9')
  15. res[0]++;
  16. else if (ch >= 'a' && ch <= 'z')
  17. res[1]++;
  18. else if (ch >= 'A' && ch <= 'Z')
  19. res[2]++;
  20. else
  21. res[3]++;
  22. }
  23.  
  24. return res;
  25. }
  26.  
  27. static void Main(string[] args)
  28. {
  29.  
  30. Console.WriteLine("A safe password is:\n" +
  31. " - Must be at least 8 characters long\n" +
  32. " - At least one upper case letter\n" +
  33. " - At least one lower case letter\n" +
  34. " - At least one number\n" +
  35. " - No other characters allowed");
  36. Console.WriteLine();
  37. Console.WriteLine("Please enter a safe password:");
  38.  
  39. // read the line entered by the user:
  40. string pass = Console.ReadLine();
  41. // send to the calculation in the function:
  42. int[] res = CountCharacterTypes(pass);
  43.  
  44. // check what is contained in the entered password:
  45. if (pass.Length < 8 || res[0] == 0 || res[1] == 0 || res[2] == 0)
  46. {
  47. Console.WriteLine();
  48. Console.WriteLine("Password has:\n" + res[0] + " digits\n" + res[1] + " Lower Case\n" +
  49. res[2] + " Upper Case\n" + res[3] + " Other");
  50. }
  51. else
  52. {
  53. Console.WriteLine("Password is safe");
  54. }
  55. Console.WriteLine();
  56. Console.WriteLine("Password must be at least 8 characters long\n" +
  57. "Password must have at least one number.\n" +
  58. "Password must have at least one lower case letter\n" +
  59. "Password must have at least one upper case letter\n" +
  60. "Password must contain only English letters and numbers");
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement