Advertisement
GabrielDas

Untitled

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