repl.it
@madaskalas/

Password Checker

C#

No description

fork
loading
Files
  • main.cs
  • main.exe
  • Tools.cs
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*

In this project you’ll make a program that measures the strength of any given password based on the following criteria. A strong password:

is at least 8 characters long
has lowercase letters
has uppercase letters
has numerical digits
has symbols, like #, ?, !
The program will ask the user to input a password, and using conditional logic and control flow, it will rate the password.

*/


/*
https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex?view=netframework-4.8#examples 
[Do it with regular expressions when you will learn about them]
*/

using System;

class MainClass {
  public static void Main (string[] args) {
			int minLength = 8;
      string uppercase = "ABCDEFGHIKLMNOPQRSTVXYZ";
      string lowercase = "abcdefghiklmnopqrstvxyz";
      string digits = "0123456789";
      string specialChars = "[email protected]\"'()*=+,-./";
      Console.Write("Enter a password: ");
      string userInput = Console.ReadLine();
      int passwordLength = userInput.Length;
      int score = 0;
      if (passwordLength >= minLength) {
        score = score + 1;
      }
      if (Tools.Contains(userInput, uppercase)) {
        score = score + 1;
      }
      if (Tools.Contains(userInput, lowercase)) {
        score = score + 1;
      }
      if (Tools.Contains(userInput, digits)) {
        score = score + 1;
    }
      if (Tools.Contains(userInput, specialChars)) {
        score = score + 1;
      }
			if (userInput == "password" || userInput == "1234") {
        score = 0;
      }
				// Final Score
        Console.WriteLine($"Score: {score}");
				// Switch Statement
				switch (score) {
        case 5:
          Console.WriteLine($"The password {userInput} is extremely strong.");
        break;
        case 4:
          Console.WriteLine($"The password {userInput} is extremely strong.");
        break;
        case 3:
          Console.WriteLine($"The password {userInput} is strong.");
        break;
        case 2:
          Console.WriteLine($"The password {userInput} is medium.");
        break;
        case 1:
          Console.WriteLine($"The password {userInput} is weak.");
        break;
        default: 
          Console.WriteLine($"The password {userInput} doesn't meet any of the standards.");
        break;
      }
  }
}
?