Tools.cs should be a separate file, correct? Here is the URL of the project. For some reason, it throws the same error. Can you give me some information about Tools.Contains ? I searched the web, but I only found the String.Contains Method.
doesn’t have to be, you could integrate this function into your class, does mean you have to make some small changes.
the codecademy project also has PasswordChecker.csproj file, maybe that is what integrate the two cs files? Some sort of project structure file? Not sure, i barely done any C#
There are a couple of ways you could incorporate the Contains method from Tools.cs
Since you already created the Tools.cs file in your project, you could just wrap your MainClass in the same namespace that the Tools class is in like so:
using System;
namespace PasswordChecker
{
class MainClass
{
public static void Main (string[] args)
{
//Main method code
}
}
}
Or, you could add the Contains method to your mainClass like so:
class MainClass
{
public static void Main (string[] args)
{
//Main method code
//Instead of Tools.Contains(arg1, arg2) you would simply use Contains(arg1, arg2)
}
//Add the Contains method here after the Main method, but still inside the MainClass class
public static bool Contains(string target, string list)
{
return target.IndexOfAny(list.ToCharArray()) != -1;
}
}
Using the second option, you could delete the Tools.cs file from your Repl.
For one, you check at the start of the password is equal to 1234 (let’s assume you also checked for password or all excluded words for now) and set the score to 0.
That’s fine, but you should take the score there and not do all the other password checks because they will give a score of at least 1 otherwise (1 for digit in the case of 1234 or 1 for lowercase in the case of password). That may have been why you was trying to do with the first else if?
With regards to checking if the password is equal to an excluded words then the easiest way is probably to have a collection of the excluded words and then check if the password is in that. This allows you to add to it or remove from it easily Vs writing extra if statements for each possible excluded word.
The Tools.Contains() method won’t work in my own independent environment when I copy and paste the code from my ‘Password Checker’ project into my own desktop Visual Studio.
The methods worked fine when I ran it on the website.
Does anyone know if the Tools.Contains(target, list) method was one created from scratch by Codecademy specifically for the ‘Password Check’ exercise?
It seems like a number of people, when they try the project on their own computers, run into a similar issue. This is probably because I didn’t clearly explain Tools.Contains().
Tools.Contains() is a custom tool provided by us. It’s defined in a separate file Tools.cs.
I’ve added some clarification to the project - hopefully it helps future learners avoid this issue!
I am stuck in this project as well and don’t know what else to do:
using System;
namespace PasswordChecker
{
class Program
{
public static void Main(string args)
{
// setting password standards
int minLength = 8;
string uppperCase = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”;
string lowerCase = “abcdefghijklmnopqrstuvwxyz”;
string digits = “0123456789”;
string specialChars = “`~!@#$%^&*()-+”;
// asking for the password
Console.Write("Enter password: ");
string userPassword = Console.ReadLine();
// BEGIN evaluating the password
int score = 0;
// first, min length
if (userPassword.Length >= minLength){
score++;
}
// then, uppercase
if (Tools.Contains(userPassword, upperCase)){
score++;
}
Console.WriteLine(score);
}
}
}
Error message: Program.cs(29,40): error CS0103: The name ‘upperCase’ does not exist in the current context [/home/ccuser/workspace/csharp-password-checker/PasswordChecker.csproj]
The build failed. Fix the build errors and run again.
Final note: I’ve made tweaks to see what else I can do and clearly the string upperCase is created above. Thoughts?
In this exercise, a bunch of spaces is supposed to return a score of 0, but if I type in 8 0’s or more it complies with the minLength requirement and scores a 1. This is obviously not ideal to have people create a password with just one number, letter or spaces repeated multiple times.
How do I have users still score 0, regardless of whether it satisfies the minLength requirement or not?
the Tools.Contains method wont work in Visual Studio unless you add it as a class.
You can do this by selecting the project tab at the top of Visual Studio, then select add Class.
You will want to name this class as Tools.cs
Then select the class by clicking on Tools.cs from the Solution explorer on the right hand side of visual studio
Inside of the class paste the following code.
using System;
using System.Collections.Generic;
using System.Text;
namespace Codecademy
{
public class Tools
{
public Tools()
{
}
public static bool Contains(string target, string list)
{
return target.IndexOfAny(list.ToCharArray()) != -1;
}
public static void ContainsTest()
{
string loudWord = "LASDAD";
string quietWord = "pssst";
string mixedWord = "lkaAWEkasfkEW";
string uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string lowercase = "abcdefghijklmnopqrstuvwxyz";
Console.WriteLine("Running \"tests...\"");
Console.WriteLine($"Should be true: {Contains(loudWord, uppercase)}");
Console.WriteLine($"Should be false: {Contains(loudWord, lowercase)}");
Console.WriteLine($"Should be false: {Contains(quietWord, uppercase)}");
Console.WriteLine($"Should be true: {Contains(quietWord, lowercase)}");
Console.WriteLine($"Should be true: {Contains(mixedWord, uppercase)}");
Console.WriteLine($"Should be true: {Contains(mixedWord, lowercase)}");
}
}
}
You also need to add “using Codecademy;” to the Program.cs underneath the ‘using system;’ part of the text
I’ve included a little more below than i needed to in the hope that it would make it clearer.
using System;
using Codecademy;
namespace PasswordChecker
{
class Program
{
public static void Main(string[] args)
If this has helped click the like button.
Ps I’m a newb, be kind