Advertisement
IvanITD

4 - Password Checker

Jan 17th, 2024
2,220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.47 KB | Source Code | 0 0
  1. namespace Password_Checker
  2. {
  3.     public class Tools
  4.     {
  5.         public Tools()
  6.         {
  7.  
  8.         }
  9.  
  10.         public static bool Contains(string target, string list)
  11.         {
  12.             return target.IndexOfAny(list.ToCharArray()) != -1;
  13.         }
  14.  
  15.         public static void ContainsTest()
  16.         {
  17.  
  18.         }
  19.     }
  20.  
  21.     internal class Program
  22.     {
  23.         static void Main(string[] args)
  24.         {
  25.             // Here we will write all the needed requirements for a newly writen password.
  26.  
  27.             int minLength = 8;
  28.             string upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  29.             string lowerCase = "abcdefghijklmnopqrstuvwxyz";
  30.             string digits = "0123456789";
  31.             string specialChars = "~`!@#$%^&*()_-+={[}]|<>.?/";
  32.  
  33.             // Now we will ask the user to enter a password and capture their input in a variable!
  34.  
  35.             Console.WriteLine("Dear user! \nPlease input your desired password!");
  36.             string userPassword = Console.ReadLine();
  37.             int passwordLength = userPassword.Length;
  38.  
  39.             // Now we need to score the users inputted password, in order to see if it meets the requirements!
  40.  
  41.             int score = 0;
  42.  
  43.             if (passwordLength >= minLength)
  44.             {
  45.                 score++;
  46.             }
  47.  
  48.             // Here we need to give a score point to the user, if he has added an upper case to the password
  49.  
  50.             bool upperCaseChecker = Tools.Contains(userPassword, upperCase);
  51.             if (upperCaseChecker == true)
  52.             {
  53.                 score++;
  54.             }
  55.  
  56.             // Here we score the user, only if he added lowe case to his password
  57.  
  58.             bool lowerCaseChecker = Tools.Contains(userPassword, lowerCase);
  59.             if (lowerCaseChecker == true)
  60.             {
  61.                 score++;
  62.             }
  63.  
  64.             //If the password contains digits, we add one point to the score!
  65.  
  66.             bool digitsChecker = Tools.Contains(userPassword, digits);
  67.             if (digitsChecker == true)
  68.             {
  69.                 score++;
  70.             }
  71.  
  72.             // Now if the password contains special characters, we need to add a point to the score!
  73.  
  74.             bool specialCharsChecker = Tools.Contains(userPassword, specialChars);
  75.             if (specialCharsChecker == true)
  76.             {
  77.                 score++;
  78.             }
  79.  
  80.  
  81.             // Another functionality for the password checker is the just "password" word usage. In that case we give the user 0 score points and we tell him that the password doesn't meet the standarts!
  82.  
  83.             if (userPassword == "password")
  84.             {
  85.                 score = 0;
  86.                 Console.WriteLine("The password doesn't meet any of the standarts!");
  87.             }
  88.             else
  89.             {
  90.  
  91.             }
  92.             // Here we need to print the total collected score, up until now!
  93.  
  94.             Console.WriteLine(score);
  95.  
  96.  
  97.             // Now that we checked our program we need to inform the user how he did with the password!
  98.  
  99.             switch (score)
  100.             {
  101.                 case 5:
  102.                 case 4:
  103.                     Console.WriteLine("The password is extremely strong!");
  104.                     break;
  105.  
  106.                 case 3:
  107.                     Console.WriteLine("The password is strong!");
  108.                     break;
  109.  
  110.                 case 2:
  111.                     Console.WriteLine("The password is medium!");
  112.                     break;
  113.  
  114.                 case 1:
  115.                     Console.WriteLine("The password is weak!");
  116.                     break;
  117.  
  118.                 default:
  119.                     Console.WriteLine("The password doesn't meet any of the standarts!");
  120.                     break;
  121.             }
  122.  
  123.             // Now we need to make some checks to the program to see if everything is working in proper order!
  124.             // 1) First try / "word" scores 1 - prints => The password is weak! (Success)
  125.             // 2) Second try / "woRD scores 2 - prints => The password is medium! (Success)
  126.             // 3) Third try / 1woRD scores 3 - prints => The password is strong! (Success)
  127.             // 4) Fourth try / 2woRDsss scores 4 - prints => The password is extremely strong! (Success)
  128.             // 5) Fifth try / 2woRDsss!  scores 5 - prints => The password is extremely strong, AGAIN! (Success)
  129.             // 6) Sixth try / " " scores 0 - prints => The password doesn't meet any of the standarts (Success)
  130.         }
  131.     }
  132. }
  133.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement