Ask coding questions

← Back to all posts
help with password security checker
ZControls_Games (18)

I know how to make it check for caps and lowercase letters and symbols
as you can see from my code but I know its not the most efficient way to do it. Does anyone have an idea?

Answered by ash15khng (684) [earned 5 cycles]
View Answer
ash15khng (684)

If you do password == "A", "B", "C" and so on it doesn't work, it would check if the password is "A" and then not do anything with "B", "C" and so on.
What you want to do is check if the password has one of the strings "A", "B" and so on. You can do that like this:

for (int i = 0; i < letters.length(); i++) {
    if (password.find(letters[i]) != string::npos) {
        cout << "1/5 done .... other text";

Not 100% sure if this works, but basically it checks every character in the string letters and checks if it is in the password. Hope this helps! (and works)

ZControls_Games (18)

OK I will accept it for now and use it after I finish [email protected]

ash15khng (684)

@ZControls_Games No problem! My C++ is pretty rusty so you should expect some errors, but if you do encounter any you can ask here!