Advertisement
Guest User

Untitled

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