Advertisement
mimitom10

04.PasswordValidator

Oct 21st, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _04.PasswordValidator
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. string password = Console.ReadLine();
  10.  
  11. bool invalidLength = isNotValidLength(password);
  12. bool invalidChars = isNotValidChars(password);
  13. bool invalidDigits = areNotTwoDigits(password);
  14.  
  15.  
  16. if (invalidLength)
  17. {
  18. Console.WriteLine("Password must be between 6 and 10 characters");
  19. }
  20. if (invalidChars)
  21. {
  22. Console.WriteLine("Password must consist only of letters and digits");
  23. }
  24. if(invalidDigits)
  25. {
  26. Console.WriteLine("Password must have at least 2 digits");
  27. }
  28. else
  29. {
  30. Console.WriteLine("Password is valid");
  31. }
  32.  
  33. }
  34.  
  35. static bool isNotValidLength(string input)
  36. {
  37. if (input.Length >= 6 && input.Length <= 10)
  38. {
  39. return false;
  40. }
  41. else
  42. {
  43. return true;
  44. }
  45. }
  46.  
  47. static bool isNotValidChars(string input)
  48. {
  49. int counter = 0;
  50. for (int i = 0; i < input.Length; i++)
  51. {
  52. if (input[i] >= 48 && input[i] <= 57
  53. || input[i] >= 65 && input[i] <= 90
  54. || input[i] >= 97 && input[i] <= 122)
  55. {
  56.  
  57. }
  58. else
  59. {
  60. counter++;
  61. }
  62. }
  63. if (counter > 0)
  64. {
  65. return true;
  66. }
  67. else
  68. {
  69. return false;
  70. }
  71. }
  72.  
  73. static bool areNotTwoDigits(string input)
  74. {
  75. int counter = 0;
  76. for (int i = 0; i < input.Length; i++)
  77. {
  78. if (input[i] >= 48 && input[i] <= 57)
  79. {
  80. counter++;
  81. }
  82.  
  83. }
  84. if (counter >= 2)
  85. {
  86. return false;
  87. }
  88. else
  89. {
  90. return true;
  91. }
  92. }
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement