Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _04_PasswordValidator
- {
- class Program
- {
- static void Main(string[] args)
- {
- string password = Console.ReadLine();
- bool isValid = true;
- isValid = PasswordLenght(password, isValid);
- isValid = OnlyLettersAndDigits(password, isValid);
- isValid = lastTwoCharecter(password, isValid);
- if (isValid)
- {
- Console.WriteLine("Password is valid");
- }
- }
- static bool PasswordLenght(string input, bool isValid)
- {
- if (input.Length < 6 || input.Length > 10)
- {
- isValid = false;
- Console.WriteLine("Password must be between 6 and 10 characters");
- }
- return isValid;
- }
- static bool lastTwoCharecter(string input, bool isValid)
- {
- int inputLenght = input.Length;
- int lastCharecter = input[inputLenght - 1];
- int beforLastChar = input[inputLenght - 2];
- if (57 < lastCharecter || lastCharecter < 48 || 57 < beforLastChar || beforLastChar < 48)
- {
- isValid = false;
- Console.WriteLine("Password must have at least 2 digits");
- }
- return isValid;
- }
- static bool OnlyLettersAndDigits(string input, bool isValid)
- {
- bool isNotValid = false;
- for (int i = 0; i < input.Length; i++)
- {
- int number = input[i];
- if (number < 48 || 57 < number && number < 65 || 90 < number && number < 97 || 122 < number)
- {
- isNotValid = true;
- }
- }
- if (isNotValid)
- {
- isValid = false;
- Console.WriteLine("Password must consist only of letters and digits");
- }
- return isValid;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement