Password checker project- I always have a strong password?

I’m having an issue on the password checker project, no matter what password I enter it says I have a strong password. I followed the tutorial: https://youtu.be/U_rcOw1aNHo
and I’m not sure where I’ve gone wrong.

using System;

namespace PasswordChecker
{
class Program
{
public static void Main(string args)
{

int minLength = 8;
string uppercase = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”;
string lowercase = “abcdefghijklmnopqrstuvwxyz”;
string digits = “0123456789”;
string specialChars = “!@#$%^&*-+”;
Console.Write("Enter a password: ");
string password = Console.ReadLine();
int score = 0;
if (password.Length >= minLength);
{
score++;

}

if (Tools.Contains (password,uppercase));
{
score++;
}
if (Tools.Contains(password, lowercase));
{
score++;
}

if (Tools.Contains(password,digits));
{
score++;
}
if (Tools.Contains(password,specialChars));
{
score++;
}
switch (score)
{
case 5:
case 4:
Console.WriteLine(“You have a very strong password!”);
break;
case 3:
Console.WriteLine(" Your password is ok.");
break;
case 2:
Console.WriteLine(“Hmm it could be stronger.”);
break;
case 1:
Console.WriteLine("Boo, this password is too weak! ");
break;
default:
Console.WriteLine(“Your password doesn’t any of the requirments!”);
break;

}
}
}
}

Run a debugger and see what the value of score is being evaluated to.

Also consider that strength of password here is a naive definition of the term. I’m saying this just in case the disclaimer is not clear enough in the lessons.

1 Like

There look to be some unnecessary characters in the code! Keep an eye out for out-of-place punctuation that might be calling an early end to commands.

Maybe your if-statements hide a secret or two?

2 Likes

Ok, I’ve been looking over my code but I still can’t figure out what I’ve done wrong. Could I have another hint?

1 Like

Not a problem! Let me see if I can write one that isn’t too leading. Or misleading! :yum:

If-statements aren’t considered standalone statements. If the logical expression suddenly terminates, it won’t do its job, and the body of the statement will still execute. In this case, your if-statements, the ones adding 1 to the value of score, are executing despite the fact that there is a logical expression giving the rules for when they should fire.

In C#, the semicolon is very frequently used to terminate lines and tell the computer the expression is finished. Take a look at your if-statements with the perspective that those will terminate an expression, potentially earlier than intended.

2 Likes

Yes! I got it to work, thank you!

1 Like