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 invalidLength = isNotValidLength(password);
- bool invalidChars = isNotValidChars(password);
- bool invalidDigits = areNotTwoDigits(password);
- if (invalidLength)
- {
- Console.WriteLine("Password must be between 6 and 10 characters");
- }
- if (invalidChars)
- {
- Console.WriteLine("Password must consist only of letters and digits");
- }
- if(invalidDigits)
- {
- Console.WriteLine("Password must have at least 2 digits");
- }
- else
- {
- Console.WriteLine("Password is valid");
- }
- }
- static bool isNotValidLength(string input)
- {
- if (input.Length >= 6 && input.Length <= 10)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- static bool isNotValidChars(string input)
- {
- int counter = 0;
- for (int i = 0; i < input.Length; i++)
- {
- if (input[i] >= 48 && input[i] <= 57
- || input[i] >= 65 && input[i] <= 90
- || input[i] >= 97 && input[i] <= 122)
- {
- }
- else
- {
- counter++;
- }
- }
- if (counter > 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- static bool areNotTwoDigits(string input)
- {
- int counter = 0;
- for (int i = 0; i < input.Length; i++)
- {
- if (input[i] >= 48 && input[i] <= 57)
- {
- counter++;
- }
- }
- if (counter >= 2)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement