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