Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace PasswordValidator
- {
- class Program
- {
- static void Main()
- {
- string password = Console.ReadLine();
- int digitsCount = 0;
- int notValidSymbols = 0;
- for (int i = 0; i < password.Length; i++)
- {
- bool validChars = ((char)password[i] >= 48 && (char)password[i] <= 57) || ((char)password[i] >= 65 && (char)password[i] <= 90) || ((char)password[i] >= 97 && (char)password[i] <= 122);
- if(!validChars)
- {
- notValidSymbols += 1;
- }
- if((char) password[i] >= 48 && (char)password [i] <= 57)
- {
- digitsCount += 1;
- }
- }
- if(password.Length < 6 || password.Length > 10)
- {
- PrintNotEnoughOrTooManyCharacters();
- }
- if(notValidSymbols > 0)
- {
- PrintNotCorrectSymbols();
- }
- if (digitsCount < 2)
- {
- PrintNotEnoughDigits();
- }
- if(password.Length >= 6 && password.Length <= 10 && notValidSymbols == 0 && digitsCount >= 2)
- {
- Console.WriteLine("Password is valid");
- }
- }
- public static void PrintNotEnoughOrTooManyCharacters()
- {
- Console.WriteLine("Password must be between 6 and 10 characters");
- }
- public static void PrintNotCorrectSymbols()
- {
- Console.WriteLine("Password must consist only of letters and digits");
- }
- public static void PrintNotEnoughDigits()
- {
- Console.WriteLine("Password must have at least 2 digits");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement