Deserboy

Password Validator

Jun 19th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.20 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. namespace ConsoleApp47
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string input = Console.ReadLine();
  10.             char[] array;
  11.             array = input.ToCharArray();
  12.             int charsNumber = 0;
  13.             bool charNumber = true;
  14.             for (int i = 0; i < array.Length; i++)
  15.             {
  16.                 charsNumber++;
  17.             }
  18.             if (charsNumber < 6 || charsNumber > 10)
  19.             {
  20.                 Console.WriteLine(PrintCharNumber(charsNumber));
  21.                 charNumber = false;
  22.             }
  23.             int digitsNumber = 0;
  24.             bool charCheck = true;
  25.             bool digitNumber = true;
  26.             for (int i = 0; i < array.Length; i++)
  27.             {
  28.                 int charNum = array[i];
  29.                 if (charNum <= 48 && charNum >= 57)
  30.                 {
  31.                     if (charNum <= 65 && charNum >= 90)
  32.                     {
  33.                         if (charNum <= 97 && charNum >= 122)
  34.                         {
  35.                             Console.WriteLine(CharsCheck());
  36.                             charCheck = false;
  37.                         }
  38.  
  39.                     }
  40.                 }
  41.                 if (charNum >= 48 && charNum <= 57)
  42.                 {
  43.                     digitsNumber++;
  44.                 }
  45.             }
  46.             if (digitsNumber < 2)
  47.             {
  48.                 Console.WriteLine(DigitsCheck());
  49.                 digitNumber = false;
  50.             }
  51.             if (digitNumber == true && charNumber == true && charCheck == true)
  52.             {
  53.                 Console.WriteLine("Password is valid");
  54.             }
  55.         }
  56.         static string PrintCharNumber(int number)
  57.         {
  58.             string output = "Password must be between 6 and 10 characters";
  59.             return output;
  60.         }
  61.         static string CharsCheck()
  62.         {
  63.             string output = "Password must consist only of letters and digits";
  64.             return output;
  65.         }
  66.         static string DigitsCheck()
  67.         {
  68.             string output = "Password must have at least 2 digits";
  69.             return output;
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment