Advertisement
Guest User

Untitled

a guest
Jun 14th, 2021
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace exercise_13
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string password = Console.ReadLine();
  11.  
  12.             if (WrongPassword(password))
  13.             {
  14.                 Console.WriteLine("Password is valid");
  15.             };
  16.         }
  17.  
  18.         static bool WrongPassword(string password)
  19.         {
  20.  
  21.             bool atLeastTwoDigits = password.All(Char.IsDigit);
  22.             bool letteranddigit = password.All(Char.IsLetterOrDigit);
  23.             bool passValidation = true;
  24.  
  25.             if (password.Length < 6 || password.Length > 10)
  26.             {
  27.                 passValidation = false;
  28.                 Console.WriteLine("Password must be between 6 and 10 characters");
  29.             }
  30.             if (!letteranddigit)
  31.             {
  32.                 passValidation = false;
  33.                 Console.WriteLine("Password must consist only of letters and digits");
  34.             }
  35.  
  36.             int count = 0;
  37.             for (int i = 0; i < password.Length; i++)
  38.             {
  39.                 char symbol = password[i];
  40.                 if (char.IsDigit(symbol))
  41.                 {
  42.                     count++;
  43.                 }
  44.             }
  45.  
  46.             if (count < 2)
  47.             {
  48.                 passValidation = false;
  49.                 Console.WriteLine("Password must have at least 2 digits");
  50.             }
  51.  
  52.             return passValidation;
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement