Hi guys! I have to write a code that checks to see if the password entered meets certain criteria and if it does not the whole function is supposed to start over. The criteria are that it must be atleast 12 characters and must have one upercase letter, one lowercase letter, one number, and one special character. I already have some of the code down but I don't know where to go from here. Any help with this would be greatly appreciated. Thanks in advance guys!!

#include <iostream>
#include <string>

using namespace std;

int main()
{
    cout << "password checker\n";
    cout << "enter a password: ";

    string password = "";
    int i = 0;
    bool length = false;
    bool upper = false;
    bool lower = false;
    bool number = false;
    bool special = false;

    getline(cin, password);

    while (length != false && upper != false && lower != false && number != false && special != false )
    {

        for (int i = 0; i < password.length; ++i)
        {

            if (password.length >= 12)
            {
                length = true;
            }
            if (password[i] >= 'a' && password[i] <= 'z')
            {
                lower = true;
            }
            if (password[i] >= 'A' && password[i] <= 'Z')
            {
                upper = true;
            }
            if (password[i] >= '0' && password[i] <= '9')
            {
                number = true;
            }
            if (password[i] == '!' || password[i] == '@' || password[i] == '#' || password[i] == '$' || password[i] == '%' || password[i] == '&' || password[i] == '^' || password[i] == '*')
            {
                special = true;
            }

        }

    }

    system("pause");
    return 0;
}

line 24 is incorrect -- password.length(); length is a function call so you need parentheses.

You might want to move the while loop on lines 21 and 22 up to be between lines 7 and 8 so that everything is inside that loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.