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 password = Console.ReadLine();
- int countOfNumbers = 0;
- bool isDigitOrLetter = true;
- bool isDigit = false;
- bool isLetter = false;
- for (int i = 0; i < password.Length; i++)
- {
- char currentSymbol = password[i];
- isDigit = Char.IsDigit(currentSymbol); // използване на готов метод за проверка на цифри
- isLetter = Char.IsLetter(currentSymbol); // използване на готов метод за проверка на букви
- if (isDigit) // ако някой от символите е цифра - броим
- {
- countOfNumbers++;
- }
- if (!isDigit && !isLetter) // ако не е нито цифра, нито буква, правим каквото трябва
- {
- isDigitOrLetter = false;
- }
- }
- if (password.Length < 6 || password.Length > 10) // проверка за дължината на паролата
- {
- Console.WriteLine("Password must be between 6 and 10 characters");
- }
- if (!isDigitOrLetter)
- {
- Console.WriteLine("Password must consist only of letters and digits");
- }
- if (countOfNumbers <= 1)
- {
- Console.WriteLine("Password must have at least 2 digits");
- }
- if (isDigitOrLetter && countOfNumbers > 1)
- {
- Console.WriteLine("Password is valid");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment