Taniaaleksandrova

Untitled

Jun 12th, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _04._Password_Validator
  4. {
  5. class Program
  6. {
  7. static bool PasswordCheckCharacter(string input)
  8. {
  9. bool trueOrFalse = true;
  10. if(!(input.Length>=6 && input.Length<=10))
  11. {
  12. Console.WriteLine("Password must be between 6 and 10 characters");
  13. trueOrFalse = false;
  14. }
  15. return trueOrFalse;
  16. }
  17. static bool PasswordCheckLettersAndDigits(string input)
  18. {
  19. bool trueOrFalse = true;
  20.  
  21. for (int i = 0; i < input.Length; i++)
  22. {
  23. char currentChar = input[i];
  24. if (!((currentChar >=48 && currentChar >= 57) || (currentChar >= 65 && currentChar <= 90) || (currentChar >= 97 && currentChar <= 122)))
  25. {
  26. Console.WriteLine("Password must consist only of letters and digits");
  27. trueOrFalse = false;
  28.  
  29. }
  30.  
  31. }
  32.  
  33. return trueOrFalse;
  34. }
  35. static bool PasswordCheckDigits(string input)
  36. {
  37. bool trueOrFalse = false;
  38. int result;
  39. int counter = 0;
  40. for (int i = 0; i < input.Length; i++)
  41. {
  42. string character = input[i].ToString();
  43. if (int.TryParse(character, out result))
  44. {
  45. counter++;
  46. }
  47. }
  48. if(counter<2)
  49. {
  50. Console.WriteLine("Password must have at least 2 digits");
  51. trueOrFalse = true;
  52. }
  53. return trueOrFalse;
  54. }
  55. static void Main(string[] args)
  56. {
  57. string input = Console.ReadLine();
  58. PasswordCheckCharacter(input);
  59. PasswordCheckDigits(input);
  60. PasswordCheckLettersAndDigits(input);
  61. if(!(PasswordCheckCharacter(input) || PasswordCheckDigits(input) || PasswordCheckLettersAndDigits(input)))
  62. {
  63. Console.WriteLine("Password is valid");
  64. }
  65.  
  66. }
  67. }
  68. }
Add Comment
Please, Sign In to add comment