Advertisement
vovanhoangtuan

Validate Password

Apr 20th, 2020
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Bai2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             while (true)
  14.             {
  15.                 string temp = Console.ReadLine();
  16.                 if (temp == "-1") break;
  17.                 if (validatePassword(temp)) Console.WriteLine("Yes");
  18.                 else Console.WriteLine("No");
  19.             }
  20.         }
  21.  
  22.         static bool checkSymbol(char input)
  23.         {
  24.             string symbol = "!@#$%^&*()";
  25.             foreach (char value in symbol)
  26.             {
  27.                 if (value == input) return true;
  28.             }
  29.             return false;
  30.         }
  31.         static bool validatePassword(string n)
  32.         {
  33.             bool haveNumber = false, haveUpper = false, haveLower = false, haveSymbol = false;
  34.             if (n.Length < 8) return false;
  35.  
  36.             foreach(char value in n)
  37.             {
  38.                 if (char.IsNumber(value)) haveNumber = true;
  39.                 if (char.IsLower(value)) haveUpper = true;
  40.                 if (char.IsUpper(value)) haveLower = true;
  41.                 if (checkSymbol(value)) haveSymbol = true;
  42.             }
  43.             if (haveNumber == true && haveUpper == true && haveLower == true && haveSymbol == true) return true;
  44.             return false;
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement