Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace PasswordValidator
- {
- class Program
- {
- static void Main(string[] args)
- {
- string text = Console.ReadLine();
- bool firstCheck = Check1(text);
- bool secondCheck = Check2(text);
- bool thirdCheck = Check3(text);
- if (firstCheck == true && secondCheck == true && thirdCheck == true)
- {
- Console.WriteLine("Password is valid");
- }
- }
- static bool Check2(string text)
- {
- for (int i = 0; i < text.Length; i++)
- {
- if (!char.IsLetterOrDigit(text[i]))
- {
- Console.WriteLine("Password must consist only of letters and digits");
- return false;
- }
- }
- return true;
- }
- static bool Check3(string text)
- {
- int digitCounter = 0;
- for (int i = 0; i < text.Length; i++)
- {
- if (char.IsDigit(text[i]))
- {
- digitCounter++;
- }
- }
- if (digitCounter >= 2)
- {
- return true;
- }
- Console.WriteLine("Password must have at least 2 digits");
- return false;
- }
- static bool Check1(string text)
- {
- if (text.Length >= 6 && text.Length <= 10)
- {
- return true;
- }
- Console.WriteLine("Password must be between 6 and 10 characters");
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement