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