Password Checker-- bug with Tools.Contains() method

This is melting my brain, and I’m convinced that this is a bug. I’m having issue with the Tools.Contains() method, and it’s not evaluating properly in CodeCademy. At line 39, where the code checks for uppercase letters, it fails to identify them every single time. In fact, the only one that DOES work is the one that checks for lowercase letters.

I’ve been trying to figure out how to get this to work in VIsualStudio, but the CodeCademy instructions reference a Tools.cs file that simply isn’t present. So I’m kind of stuck, and very frustrated! Please help!

using System;

namespace PasswordChecker
{
  class Program
  {
    public static void Main(string[] args)
    {
      //VARS
      //
      int minLength = 8, score = 0;
      //uppercase
      string uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
      Console.WriteLine($"uppercase = {uppercase}");
      //lowercase
      string lowercase = uppercase.ToLower();
      Console.WriteLine($"lowercase = {lowercase}");
      //digits
      string digits = "0123456789";
      Console.WriteLine($"digits = {digits}");
      //specialChars  
      string specialChars = "!@#$%^&*()_+=~`";
      Console.WriteLine($"specialChars = {specialChars}");

      //input
      Console.WriteLine("Please enter a password, which we'll score for strength:");
      string password = Console.ReadLine();
      int passwordLength = password.Length;
      Console.WriteLine($"passwordLength = {passwordLength}");

      //Check length
      if (passwordLength >= minLength)
      {
        Console.WriteLine($"Password length ({passwordLength}) is greater than or equal to {minLength}.");
        score++;
      }
      Console.WriteLine(score);
      //Check for uppercase
      if (Tools.Contains("password", uppercase))
      {
        Console.WriteLine("Password contains uppercase letters.");
        score++;
      }
      else
      {
        Console.WriteLine("Password does not contain uppercase letters.");
      }
      Console.WriteLine(score);
      //Check for lowercase
      if (Tools.Contains("password", lowercase))
      {
        Console.WriteLine("Password contains lowercase letters.");
        score++;
      }
      else
      {
        Console.WriteLine("Password does not contain lowercase letters.");
      }
      Console.WriteLine(score);
      //Check for digits
      if (Tools.Contains("password", digits))
      {
        Console.WriteLine("Password contains digits.");
        score++;
      }
      else
      {
        Console.WriteLine("Password does not contain digits.");
      }
      Console.WriteLine(score);
      //Check for special chars
      if (Tools.Contains("password", specialChars))
      {
        Console.WriteLine("Password contains special characters.");
        score++;
      }
      else
      {
        Console.WriteLine("Password does not contain special characters.");
      }
      Console.WriteLine(score);






    }
  }
}

Hello @arraysurfer07356, welcome to the forums! This thread might be of interest to you (especially the third post):


Also, when you check to see if password contains any of these things, you are not passing in the variable password, which stores the password given by the user, but you are passing in a string "password". Therefore, every time you run the program, it just checks the string "password" against all of the conditions,

1 Like

Also, when you check to see if password contains any of these things, you are not passing in the variable password , which stores the password given by the user, but you are passing in a string "password" . Therefore, every time you run the program, it just checks the string "password" against all of the conditions,

Mother of pearl. I feel like a dingus! I was very much following the syntax in the instructions and just assuming that this was the syntax that the method preferred-- but that makes complete sense.

Hello @arraysurfer07356, welcome to the forums! This thread might be of interest to you (especially the third post):

I actually saw this thread, but couldn’t actually find any information about where to download Tools.cs. That user makes it sound like it’s very obviously available, but I don’t see it anywhere. Is it supposed to show up as a tab next to Program.cs?

EDIT: I think I see what you mean. So the only way to access the contents of that file is through the console.

2 Likes

I’m wondering the same. I can’t find Tools.cs and there is no instruction on where to find it. Please let me know.

If you see the thread, if you type cat Tools.cs, it’ll print out the contents of the Tools.cs file, and you can copy/paste that into the file you want it in.

Thank you! :slight_smile: Much appreciated!

1 Like