Creating a Login System

I'm trying to make a login system with usernames, passwords, and individual permissions as a little project while I learn c ++. After the username and password are validated, how do I clear the console of previous information?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <string>
using namespace std;
string username;
string password;
string passwordList[1] = {"Nine"};
string usernameList[1] = {"James"};
int testArray = 0;
bool ValidUser;
void adminMenu()
{
    int option;
    cout << "Welcome to the Administrator menu." << "\n" << "Please choose an option." << "\n";
    cout << "1. Add User" << "\n";
    cout << "2. Remove User" << "\n";
    cout << "3. Add file to directory";
    cin >> option;

}
bool validationTest()
{
    cout << "What is your user name " << "\n";
    cin >> username;
    cout << "What is your password " << "\n";
    cin >> password;
    for(testArray = 0; testArray < sizeof(passwordList); testArray++)
    {
        if(username == usernameList[testArray] && password == passwordList[testArray])
        {
            ValidUser = true;
        }
        else
        {
            ValidUser = false;
            return(0);
        }
    }
    return ValidUser;
}
int main ()
{
    validationTest();
    if(ValidUser)
    {
        adminMenu();
    }
    else
    {

    }

}
Last edited on
The usernameList is size 0. Also, take a look at http://www.cplusplus.com/forum/general/33669/
Last edited on
ats15.

I updated the code to.

1
2
string passwordList[1] = {"Nine"};
string usernameList[1] = {"James"};


It works now, but no matter what it always prints out invalid password. And the program stops working.
So I have a few questions:
1. Is there a way to print out what is making it stop working?
2. How can I create a dynamic array that allows an admin , through the admin menu and a method, to add values into the password and username arrays?
Updated OP ^^^^
Familiarize yourself with vectors.

http://www.cplusplus.com/reference/vector/vector/

For what your are trying to do you need only be familiar with one method from this class,push_back.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<vector>
#include<iostream>
#include<string>

using namespace std;


int main()
{
vector<string>passwordlist;
vector<string>usernamelist;
string info;
do
{
cout<<"Add a username then password.\n";
cout<<"Enter user name: ";
cin>>info;
usernamelist.push_back(info);
cout<<"Enter password: ";
cin>>info;
passwordlist.push_back(info);

cout<<"Showing user names and passwords entered...\n";
//do not use sizeof use size method for vectors or size()/length() for string object
for(int i=0; i<usernamelist.size() && i < passwordlist.size();i++)
{
cout<<"User Name: "<<usernamelist[i];
cout<<"\nPassword: "<<passwordlist[i]<<"\n";
}

cout<<"\nContinue entering new usernames and passwords?";
cin>>info;
}while(info=="yes");


}


Last edited on
@cody
Thank you very much I'll study that.

I have another question:

I plan on creating a GUI for this program. I'm also going to add different permission levels for users. Should I create different files for the methods and just have one main file? Ifyes, please link me to some useful resources that you may have.

Thanks

EDIT: I'm assuming I can use erase() along with a search function I will have to create in order to delete elements?
Last edited on
As of now, I'm getting an error that says.

@10 |error: 'usernamelist' does not name a type|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include<vector>
#include<iostream>
#include<string>
using namespace std;
vector <string> passwordlist;
vector <string> usernamelist;
string adminUser[1] = {"James"};
string adminPass[1] = {"Nine"};
passwordlist.assign(adminPass, adminPass+1);
usernamelist.assign(adminUser, adminUser+1);
string UserEntered;
string PassEntered;
bool ValidUser;

bool signIn()
{
    cout << "Please sign in." << endl;
    cout << "Username: " << endl;
    cin >> UserEntered;
    cout << "Password: " << endl;
    cin >> PassEntered;

    for(int y = 0; y < passwordlist.size; y++)
    {
        if(UserEntered == usernamelist[y] && PassEntered == passwordlist[y])
        {
            ValidUser = true;
        }
        else if(UserEntered != usernamelist[y] || PassEntered != passwordlist[y])
        {
            cout << "Invalid Information";
            ValidUser = false;
        }
    }
    return ValidUser;
}
void adminMenu()
{
    int option;
    cout << "Welcome to the Administrator menu." << "\n" << "Please choose an option." << "\n";
    cout << "1. Add User" << "\n";
    cout << "2. Remove User" << "\n";
    cout << "3. Add file to directory";
    cin >> option;
    switch (option)
    {
    case 1:
        addUser();
        breakl
    case 2:
        //removeUse();
    }

}
void addUser()
    {

        cout << "Please verify your username and password." << endl;
        cout << "Username: " << endl;
        cin >> UserEntered;
        cout << "Password: " << endl;
        cin >> PassEntered;

        string info;
    do
    {
        cout << "Add a username then password.\n";
        cout << "Enter user name: ";
        cin >> info;
        usernamelist.push_back(info);
        cout << "Enter password: ";
        cin >> info;
        passwordlist.push_back(info);
        cout << "Showing user names and passwords entered...\n";
        for(int i = 0; i <usernamelist.size() && i < passwordlist.size(); i++)
            {
                cout << "User Name: " << usernamelist[i] << endl;
                cout << "Password: " << passwordlist[i] << endl;
            }
        cout << "\nContinue entering new usernames and passwords?";
        cin >> info;
    }
    while(info == "yes");
    }
int main()
{

}
Last edited on
Also, would it be possible to use Python & C++ to save data to a file?
Like creating a folder and within that folder every username has his own .txt file?
Within that txt file, it lists all of the users information... user, pass, privileges etc.

How can I do this?
bump
Anyone
Topic archived. No new replies allowed.