Post: [OpenSource-C++] Account database system
02-06-2011, 12:48 AM #1
(adsbygoogle = window.adsbygoogle || []).push({}); Took 45 minutes to create, the good thing about this, is it can be integrated with C++ games to create a way of a log in system.

    #include <iostream>
#include <string>
#include <map>
#include "drawMenu.h"

class CLogin
{
public:
short index;
map <short,string> username;
map <string,string> password;
string logInStatus;
void addUser();
void delUser(short id);
void display(short id);
void displayAll();
void changeUser(short id);
void logOut();
void handel(short id,bool& quit);
}storage;
void CLogin::addUser()
{
string tempUser,tempPass;
bool doContinue=0;

for(;Winky Winky
{
system("CLS");
cout<<"\n\tEnter a username: ";
getline(cin,tempUser);

if(tempUser=="")
{
system("CLS");
cout<<"\n\tNo username entered!";
Sleep(2000);
continue;
}

doContinue=0;

for(int i=index;i>0;i--)
if(username[i]==tempUser)
{
system("CLS");
cout<<"\n\tUser already exists!";
Sleep(2000);
doContinue=1;
}
if(doContinue)
continue;

for(;Winky Winky
{
system("CLS");
cout<<"\n\tEnter a password: ";
getline(cin,tempPass);

if(tempPass=="")
{
system("CLS");
cout<<"\n\tNo password entered!";
Sleep(2000);
continue;
}

break;
}
break;
}
index++;
username[index] = tempUser;
password[tempUser] = tempPass;
}
void CLogin::delUser(short id)
{
if(username[id]==logInStatus)
logInStatus = "Not Logged In";
for(int i=id;i<=index;i++)
{
username[i]=username[i+1];
password[username[i]]=password[username[i+1]];

username.erase (i+1);
password.erase (username[i+1]);
}
index--;
}
void CLogin::display(short id)
{
system("CLS");
cout<<"\n\tAccount id: "<<id;;
cout<<"\n\tAccount name: "<<username[id];
cout<<"\n\tAccount pass: "<<password[username[id]];
cout<<"\n\n\t";
system("PAUSE");
}
void CLogin::handel(short id,bool& quit)
{
if(id>index)
{
quit = 1;
return;
}

string message="Edit user: ";
message+=username[id];
bool boolReturn = 0;

for(;Winky Winky
{
system("CLS");
cout<<endl;

switch(drawMenu(message,"Display details|Delete|Log on|Return",1))
{
case 1: display(id); break;
case 2: delUser(id); boolReturn=1; break;
case 3: changeUser(id); break;
case 4: boolReturn=1; break;
}
if(boolReturn)
return;
}
}
void CLogin::displayAll()
{
string users;
bool secondLayerQuit = 0;

for(;Winky Winky
{
system("CLS");
users = "";
if(index>0)
{
users+=username[1];
for(int i=2;i<index;i++)
{
users+="|";
users+=username[i];
}
if(index>=2)
{
users+="|";
users+=username[index];
}
users+="|";
users+="Return";
}
else
{
cout<<"\n\tNo users in the database!";
cout<<"\n\t";
system("PAUSE");
return;
}
cout<<endl;
handel(drawMenu("Users in the database",users,1),secondLayerQuit);
if(secondLayerQuit)
return;
}
}
void CLogin::changeUser(short id){
logInStatus=username[id];}
void CLogin::logOut(){
logInStatus="Not logged in";}
int main()
{
storage.logInStatus = "Not logged in";
string message;
for(;Winky Winky
{
system("CLS");
message = "";
message+="Log in system made by TheUberFail, Log in status: ";
message+=storage.logInStatus;
cout<<"\n";
switch(drawMenu( message,
"Display Users|Create user|Log out|Exit",
1)
)
{
case 1: storage.displayAll(); break;
case 2: storage.addUser(); break;
case 3: storage.logOut(); break;
case 4: return 0;
}
}
}



Any feedback of improvements, new features are welcome!

Source code + EXE You must login or register to view this content.
Last edited by TheUberFail ; 02-06-2011 at 12:57 AM.

The following 3 users say thank you to TheUberFail for this useful post:

fightinillini94, jackrtk, Ritztro
02-06-2011, 02:46 AM #2
Ritztro
I am a Game Developer
Originally posted by TheUberFail View Post
Took 45 minutes to create, the good thing about this, is it can be integrated with C++ games to create a way of a log in system.

    #include <iostream>
#include <string>
#include <map>
#include "drawMenu.h"

class CLogin
{
public:
short index;
map <short,string> username;
map <string,string> password;
string logInStatus;
void addUser();
void delUser(short id);
void display(short id);
void displayAll();
void changeUser(short id);
void logOut();
void handel(short id,bool& quit);
}storage;
void CLogin::addUser()
{
string tempUser,tempPass;
bool doContinue=0;

for(;Winky Winky
{
system("CLS");
cout<<"\n\tEnter a username: ";
getline(cin,tempUser);

if(tempUser=="")
{
system("CLS");
cout<<"\n\tNo username entered!";
Sleep(2000);
continue;
}

doContinue=0;

for(int i=index;i>0;i--)
if(username[i]==tempUser)
{
system("CLS");
cout<<"\n\tUser already exists!";
Sleep(2000);
doContinue=1;
}
if(doContinue)
continue;

for(;Winky Winky
{
system("CLS");
cout<<"\n\tEnter a password: ";
getline(cin,tempPass);

if(tempPass=="")
{
system("CLS");
cout<<"\n\tNo password entered!";
Sleep(2000);
continue;
}

break;
}
break;
}
index++;
username[index] = tempUser;
password[tempUser] = tempPass;
}
void CLogin::delUser(short id)
{
if(username[id]==logInStatus)
logInStatus = "Not Logged In";
for(int i=id;i<=index;i++)
{
username[i]=username[i+1];
password[username[i]]=password[username[i+1]];

username.erase (i+1);
password.erase (username[i+1]);
}
index--;
}
void CLogin::display(short id)
{
system("CLS");
cout<<"\n\tAccount id: "<<id;;
cout<<"\n\tAccount name: "<<username[id];
cout<<"\n\tAccount pass: "<<password[username[id]];
cout<<"\n\n\t";
system("PAUSE");
}
void CLogin::handel(short id,bool& quit)
{
if(id>index)
{
quit = 1;
return;
}

string message="Edit user: ";
message+=username[id];
bool boolReturn = 0;

for(;Winky Winky
{
system("CLS");
cout<<endl;

switch(drawMenu(message,"Display details|Delete|Log on|Return",1))
{
case 1: display(id); break;
case 2: delUser(id); boolReturn=1; break;
case 3: changeUser(id); break;
case 4: boolReturn=1; break;
}
if(boolReturn)
return;
}
}
void CLogin::displayAll()
{
string users;
bool secondLayerQuit = 0;

for(;Winky Winky
{
system("CLS");
users = "";
if(index>0)
{
users+=username[1];
for(int i=2;i<index;i++)
{
users+="|";
users+=username[i];
}
if(index>=2)
{
users+="|";
users+=username[index];
}
users+="|";
users+="Return";
}
else
{
cout<<"\n\tNo users in the database!";
cout<<"\n\t";
system("PAUSE");
return;
}
cout<<endl;
handel(drawMenu("Users in the database",users,1),secondLayerQuit);
if(secondLayerQuit)
return;
}
}
void CLogin::changeUser(short id){
logInStatus=username[id];}
void CLogin::logOut(){
logInStatus="Not logged in";}
int main()
{
storage.logInStatus = "Not logged in";
string message;
for(;Winky Winky
{
system("CLS");
message = "";
message+="Log in system made by TheUberFail, Log in status: ";
message+=storage.logInStatus;
cout<<"\n";
switch(drawMenu( message,
"Display Users|Create user|Log out|Exit",
1)
)
{
case 1: storage.displayAll(); break;
case 2: storage.addUser(); break;
case 3: storage.logOut(); break;
case 4: return 0;
}
}
}



Any feedback of improvements, new features are welcome!

Source code + EXE You must login or register to view this content.


Very nice! Tried it out and it worked like a charm! BTW what compiler are you using? I want to work with you on my game. Learn Opengl and sfml lol
02-06-2011, 10:33 AM #3
Originally posted by Dutch View Post
Very nice! Tried it out and it worked like a charm! BTW what compiler are you using? I want to work with you on my game. Learn Opengl and sfml lol


Thanks, Im using DevCpp at the moment, been trying for ages to get SFML working with Code::Blocks, the official tutorials dont help, and youtube has no tutorials either. me == :n00b: Happy
02-06-2011, 04:50 PM #4
Girby2K11
☮ ☯ ☢ ✔ ➝
i like this program just scrolling through the .cpp it looks like a book lol, could we store our passwords in it incase we forget.
02-06-2011, 07:23 PM #5
Originally posted by Girby2K11 View Post
i like this program just scrolling through the .cpp it looks like a book lol, could we store our passwords in it incase we forget.


I could modify it to store passwords, although they would be in files that can be accessed and viewed, i would have to learn how to add encryption to them.
02-08-2011, 11:52 PM #6
jackrtk
haters gonna' hate
epic menu!
03-01-2011, 08:55 PM #7
kiwimoosical
Bounty hunter
Originally posted by TheUberFail View Post
I could modify it to store passwords, although they would be in files that can be accessed and viewed, i would have to learn how to add encryption to them.


    
for(int x = 0; x < sizeof(password)/sizeof(char); x++)
password[x] << 7; //encrypt, extremely simple.


for(int x = 0; x < sizeof(password)/sizeof(char); x++)
password[x] >> 7; //decrypt.


Also, basic OOP, make the classes have nothing to do with your UI (Console in this case). Also, System calls are bad.

You must login or register to view this content.
03-01-2011, 09:51 PM #8
Originally posted by kiwimoosical View Post
    
for(int x = 0; x < sizeof(password)/sizeof(char); x++)
password[x] << 7; //encrypt, extremely simple.


for(int x = 0; x < sizeof(password)/sizeof(char); x++)
password[x] >> 7; //decrypt.


Also, basic OOP, make the classes have nothing to do with your UI (Console in this case). Also, System calls are bad.

You must login or register to view this content.


That encryption is too simple and people can easily decode it by looking at it :P
03-01-2011, 09:54 PM #9
kiwimoosical
Bounty hunter
Originally posted by TheUberFail View Post
That encryption is too simple and people can easily decode it by looking at it :P


I know, I could write a better encryption. XOR is a great encryption, simplistic but great xD
03-02-2011, 08:50 AM #10
Originally posted by kiwimoosical View Post
I know, I could write a better encryption. XOR is a great encryption, simplistic but great xD


Try this, its what i use and it works great Smile
You must login or register to view this content.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo