Basic password authentication system app This is a console app I wrote for an end-of-chapter assignment in Jumping into C++. The parameters were for it to have a basic password system, and if you are eager, a multiple password / username system.  I am going through this book completely on my own free will.  It's not through a school assignment or whatnot.

It works quite well, but as I have a limited programming background, I wanted to post it here so any bad techniques or poor syntax could be brought to my attention.

#include &lt;iostream&gt;

using namespace std;

string usrnam[] = { "admin", "user", "" };
string pasword[] = { "root", "default", ""};

string temp_pass;
string temp_usr;

bool loggedin;

int n = sizeof(usrnam) / sizeof(string);

int findPassword( string str[], int array_size, string query )
{
    for ( int i = 0; i &lt; array_size; i++ )
    {
        if ( str[i] == query )
    {
        return i;
    }
}
}

int commandC()
{
    int stage;
    cout &lt;&lt; "Enter '1' for calculator: ";
    cin &gt;&gt; stage;
    switch(stage)
{
    case 1: {
        cout &lt;&lt; endl;
        cout &lt;&lt; "Not fully developed" &lt;&lt; endl &lt;&lt; endl;

    }
}

cout &lt;&lt; "_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-";
}

void login(string user, string pass){
     if ( pass == pasword[findPassword(usrnam, n, user)] )
     {
        cout &lt;&lt; "Logged in as " &lt;&lt; user &lt;&lt; endl &lt;&lt; endl;
        loggedin = true;
        commandC();
     }
}

void registerUser()
{
    string answer;
    cout &lt;&lt; "No matches found in the database...would you like to make new account? (Y/N)";
    cin &gt;&gt; answer;
    if (answer == "y" || answer == "Y")
    {
        cout &lt;&lt; "Please enter a username: ";
        cin &gt;&gt; usrnam[n-1];
        cout &lt;&lt; "Please enter a password: ";
        cin &gt;&gt; pasword[n-1];

        login(usrnam[n-1],pasword[n-1]);
    }
}

int main()
{
    cout &lt;&lt; "Enter username: ";
    cin &gt;&gt; temp_usr;
    cout &lt;&lt; "Enter password; ";
    cin &gt;&gt; temp_pass;

    login(temp_usr,temp_pass);

    if(!loggedin)
        registerUser();
}
Try using std::vector instead of arrays. As a result, you'll not be required to keep track of the array_size in a separate variable like n in your case.

Something like this:

std::vector&lt;std::string&gt; username;
username.push_back("admin");
//other entries go here
std::vector&lt;std::string&gt; password;
password.push_back("root");
//other entries go here


Then, the size of the std::vector is given by size().
Try to use proper names as variables. Avoid wrong spellings or short-names. Exact variable names make the code easy to understand, as the name represents the actual concept the variable is referring to.
Also, in registerUser() the variable answer can just be a char. This will help in saving a little memory.
Like:

char answer;
std::cin&gt;&gt;answer;
if(answer=='y' || answer=='Y')
{
    //code goes here
}

In your code, the method commandC() is defined to return an int. But it doesn't do so. Make the return type void instead.

void CommandC()
{
    //code goes here
}

Also, the main() method is defined to return an int too. It is a good practice to declare it like that, but make sure to return an integer. 0 (zero) is preferred as it refers to successful completion of main().

int main()
{
    //code goes here
    return 0; //indicates successful termination
}