Good way to start a login system

Hello I am trying to wonder how would someone go about starting a login system? Just want criticism on how this looks so far it is far from complete just want the most constructive criticism throw it at me.
StudentID
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
  #include "StudentsID.h"
#include <iostream>
using namespace std;

//Created by Justin
StudentsID::StudentsID()
{
    password = NULL;
    username;

}

void StudentsID::Displayusername(string TheUsername)
{

   for (int i = 0; i < username.size(); i++)
    cout << username[i] << endl;
}
vector <string> StudentsID::getusername()
{
return username;
}
void StudentsID::Adduser(string user)
{
    username.push_back(user);
}
void StudentsID::setpassword(bool *ThePassword)
{
    *ThePassword = &password;

}
bool StudentsID::Getpassword()
{
    
    if (password == password)
    {
        return true;
    }
    else
    {
        return false;
        return 1;
    }
    return password;
}

StudentID.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef STUDENTSID_H
#define STUDENTSID_H
#include <iostream>
#include <vector>
using namespace std;
class StudentsID
{
    public:
        StudentsID();
        void setpassword(bool *ThePassword);
        bool Getpassword();
        void Displayusername(string TheUsername);
        vector <string> getusername();
        void Adduser (string user);
    protected:

    private:
        bool password;
       vector <string> username;

};

#endif // STUDENTSID_H

--Blackhart
why are you using pointers? surely the password should be string?

and this:
1
2
       return false;
        return 1;

make no sense.

You need a mechanism of mapping the user to their password (std::map maybe?)

edit:

These:

1
2
3
4
5
6
7
void StudentsID::Displayusername(string TheUsername)
{

   for (int i = 0; i < username.size(); i++)
    cout << username[i] << endl;
}


are not doing what you think they are. There is not point in iterating through all the characters in a username, you can just cout the whole thing in one go.

perhaps you meant something like this:

1
2
3
4
5
6
7
8
void StudentsID::Displayusernames(vector<string> usernames)
{

   for (int i = 0; i < usernames.size(); i++)
   {
       cout << username[i] << endl;
   }
}

? i.e. display all the usernames in your vector?
Last edited on
Thanks yeah I noticed some of these mistakes I will fix them.
Topic archived. No new replies allowed.