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 password = Console.ReadLine();
- int countOfNumbers = 0;
- int countOfChecks = 0;
- bool isCheckForSize = true;
- bool isCheckForLetters = false;
- if (password.Length < 6 || password.Length > 10) // проверка за дължината на паролата
- {
- Console.WriteLine("Password must be between 6 and 10 characters");
- isCheckForSize = false;
- }
- for (int i = 0; i < password.Length; i++)
- {
- char currentLetter = password[i];
- if (currentLetter >= 48 && currentLetter <= 57) // проверка за цифри в паролата
- {
- countOfNumbers++;
- }
- if ((currentLetter >= 32 && currentLetter <= 47) || (currentLetter >= 58 && currentLetter <= 64) || (currentLetter >= 91 && currentLetter <= 96) || (currentLetter >= 123)) // проверка за други символи
- {
- if (countOfChecks == 1)
- {
- continue;
- }
- Console.WriteLine("Password must consist only of letters and digits");
- countOfChecks++;
- }
- if ((currentLetter >= 65 && currentLetter <= 90) || (currentLetter >= 97 && currentLetter <= 122)) // проверка за букви
- {
- isCheckForLetters = true;
- }
- }
- if (countOfNumbers < 2)
- {
- Console.WriteLine("Password must have at least 2 digits");
- }
- if (isCheckForLetters == false)
- {
- if (countOfChecks == 0)
- {
- Console.WriteLine("Password must consist only of letters and digits");
- }
- }
- if (isCheckForSize && countOfChecks == 0 && isCheckForLetters && countOfNumbers >= 2)
- {
- Console.WriteLine("Password is valid");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement