C# Password Check Exercise

Hi,

I am pulling my hair out with this exercise because if the hints still don’t make sense, then you cant continue unless you check all the boxes, which then enables you to move on however, without knowing the solution for that previous exercise! The step by step ‘Run’ method is much better, but even still, if you press ‘Give me the solution’, it hands out the WHOLE solution of the exercise, which is unhelpful because I didnt get to practice it step by step…Can you please email the full solution code for the C# Password Checker exercise, otherwise I cannot continue. Thanks.

1 Like

Why would you need the full solution mailed if you can get it with solution button? You can always copy your code first to make a back-up.

if you want help in steps, you can come to the forum. See this topic:

How to ask good questions (and get good answers)

to see how to make good posts (to get good replies)

1 Like

I’m having a mistake with the password as in when I put in my password:
thatsallfolks
It says the score is 1 while the hint says the score will come out as 2.
Why is this?

Would have to see your code in order to help.

exercise url: https://www.codecademy.com/courses/learn-c-sharp/projects/csharp-password-checker

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 = "#?!,-'/`_*$";
      string password = "2woRDsss";
      int score = 0;
      if ((score) >= (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++;
      }
           
      Console.WriteLine(password);
      Console.WriteLine(score);
      
      switch (score) 
      {
        case 5:
        case 4:
          Console.WriteLine("This is an extremely strong password");
          break;
        case 3:
          Console.WriteLine("This is a strong password");
          break;
        case 2:
          Console.WriteLine("This is an average password");
          break;
        case 1:
          Console.WriteLine("This is a weak password");
          break;
        default:
          Console.WriteLine("This password doesn't meet the standards");
          break;
      } 
      Console.ReadLine();
    }
  }
}

You are missing adding 1 point to each password entered due to the line mentioned above. Happy Coding!

Thanks for reminding me to change it.

1 Like

Why is it “if score >= minLength” and not “password.length >= minLength”? That’s what I used my first time through, and it works. The highest score you can get using score >= minLength is 4, how can that statement ever return true? Maybe I’m having a giant noob moment here but that doesn’t make sense to me.

Hello @jbendz. Welcome to the forum.

if (password.Length >= minLength)
{
  score++;
} 

Not sure why you’re asking, but you are correct. It should be as you stated, and I’ve re-illustrated above. There is no need to check if score > minLength.

I have finished this exercise but need some help with regular expressions(Regex); I am not sure how to change a code, for example:

if (!Tools.Contains(password, upperCase))
{
Console.WriteLine(“Password does not contain an uppercase letter, INSECURE!”);
}

into another code that uses Regex to check for password.

Btw, side question is: What is tools.contain? is this “tools” a method that is only built in CodeAcademy program? Or it can be called up using System in visual studio?

Thank you!

If my question is not clear, please write responses tell me so. I will make it more clear.

Thanks, and I was asking because in example two posts above me it was shown as score >= minLength. I came to the forum for entirely different reason, but when I saw that it confused me and I thought I might be missing something. Thank you for the response.

Oh. Yeah, that wasn’t an example of what to do. It was code that needed fixing :slightly_smiling_face: