Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace P04PasswordValidator
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- if (PasswordCheckerFirstRule(input)==false)
- {
- Console.WriteLine("Password must be between 6 and 10 characters");
- }
- if (PasswordCheckerSecondRule(input)==false)
- {
- Console.WriteLine("Password must consist only of letters and digits");
- }
- if (PasswordCheckerThirdRule(input)==false)
- {
- Console.WriteLine("Password must have at least 2 digits");
- }
- if (PasswordCheckerFirstRule(input) == true
- && PasswordCheckerSecondRule(input) == true
- && PasswordCheckerThirdRule(input) == true)
- {
- Console.WriteLine("Password is valid");
- }
- }
- static bool PasswordCheckerFirstRule(string password)
- {
- bool isBetween6and10=true;
- if(password.Length < 6 || password.Length > 10)
- {
- isBetween6and10 = false;
- }
- return isBetween6and10;
- }
- static bool PasswordCheckerSecondRule(string password)
- {
- bool onlyLettersAndNumbers = true;
- for (int i = 0; i < password.Length; i++)
- {
- if (((int)password[i] < 48) ||
- ( (int)password[i] > 57 && (int)password[i] < 65 ||
- (int)password[i] > 90) && (int)password[i] < 97 ||
- (int)password[i] > 122)
- {
- onlyLettersAndNumbers = false;
- }
- }
- return onlyLettersAndNumbers;
- }
- static bool PasswordCheckerThirdRule(string password)
- {
- bool digitsCount = false;
- bool areDigitsCount2 = false;
- char[] digits = new char[password.Length];
- int count = 0;
- for(int i = 0; i < password.Length; i++)
- {
- digits[i] = password[i];
- digitsCount= "0123456789".IndexOf(digits[i]) >= 0;
- if (digitsCount)
- {
- count++;
- }
- }
- if (count >= 2)
- {
- areDigitsCount2 = true;
- }
- return areDigitsCount2;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement