Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace PasswordValidator
- {
- class Program
- {
- static void Main(string[] args)
- {
- string password = Console.ReadLine();
- if (CheckResult(password))
- {
- Console.WriteLine("Password is valid");
- }
- else
- {
- if (!CheckLenght(password))
- {
- Console.WriteLine("Password must be between 6 and 10 characters");
- }
- if (!CheckSymbol(password))
- {
- Console.WriteLine("Password must consist only of letters and digits");
- }
- if (!CheckDigits(password))
- {
- Console.WriteLine("Password must have at least 2 digits");
- }
- }
- }
- static bool CheckResult(string pass)
- {
- return CheckLenght(pass) && CheckSymbol(pass) && CheckDigits(pass);
- }
- static bool CheckLenght(string pass)
- {
- return pass.Length >= 6 && pass.Length <= 10;
- }
- static bool CheckSymbol(string pass)
- {
- return new Regex("[a-zA-Z0-9 -]+").Replace(pass, "") == "";
- }
- static bool CheckDigits(string pass)
- {
- return pass.Count(x => x >= '0' && x <= '9') >= 2;
- }
- }
- }
Add Comment
Please, Sign In to add comment