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
03-02-2011, 08:05 PM #11
kiwimoosical
Bounty hunter
Originally posted by TheUberFail View Post
Try this, its what i use and it works great Smile
You must login or register to view this content.


Ehh... All you do is pass the string by reference to a function that converts the string using arithmatic shit. Use bit wise operation if your going to do an encryption. That's more easily deciphered than mine.
I strongly recommend XOR encryption, simplistic, yet extremely difficult to decrypt as it is key based. Key isn't a fixed length either, so yeah, lol. Trust me, use it Happy

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo