Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace ConsoleApp47
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- char[] array;
- array = input.ToCharArray();
- int charsNumber = 0;
- bool charNumber = true;
- for (int i = 0; i < array.Length; i++)
- {
- charsNumber++;
- }
- if (charsNumber < 6 || charsNumber > 10)
- {
- Console.WriteLine(PrintCharNumber(charsNumber));
- charNumber = false;
- }
- int digitsNumber = 0;
- bool charCheck = true;
- bool digitNumber = true;
- for (int i = 0; i < array.Length; i++)
- {
- int charNum = array[i];
- if (charNum <= 48 && charNum >= 57)
- {
- if (charNum <= 65 && charNum >= 90)
- {
- if (charNum <= 97 && charNum >= 122)
- {
- Console.WriteLine(CharsCheck());
- charCheck = false;
- }
- }
- }
- if (charNum >= 48 && charNum <= 57)
- {
- digitsNumber++;
- }
- }
- if (digitsNumber < 2)
- {
- Console.WriteLine(DigitsCheck());
- digitNumber = false;
- }
- if (digitNumber == true && charNumber == true && charCheck == true)
- {
- Console.WriteLine("Password is valid");
- }
- }
- static string PrintCharNumber(int number)
- {
- string output = "Password must be between 6 and 10 characters";
- return output;
- }
- static string CharsCheck()
- {
- string output = "Password must consist only of letters and digits";
- return output;
- }
- static string DigitsCheck()
- {
- string output = "Password must have at least 2 digits";
- return output;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment