Advertisement
marto9119

Untitled

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