#include <cstdlib>
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
string pass;
string username;
bool admin;
bool blogin = false;
//Hack protection, because blogin shouldnt = true yet. Now if you call a function that does this and u use it multiple times, dont do this.
if(blogin == true || admin == true)
{
return 0;
}
map <string,string> login;
map <string,string> adminlogin;
adminlogin["Dutch"] = "password"; // Dutch (the username) is the name of the map element and "password" is the actual string for the password.
while(blogin == false)
{
cout << "Please enter your username" << endl;
cin >> username;
cout << "Please enter you pass" << endl;
cin >> pass;
if(pass == adminlogin[username])
{
cout << "Welcome " << username << " You are an admin" << endl;
admin = true; // YOu can give them special permissions if this is true..
blogin = true;
}
else if(pass == login[username])
{
cout << "Welcome " << username << endl;
blogin = true;
}
else
{
cout << "Login Failed please try again" << endl;
system("cls");
}
}
return 0;
}
#include <iostream>
#include <windows.h>
#include <map>
#include "drawMenu.h"
using namespace std;
class CLogin
{
public:
map<string,string> account;
map<int,string> index;
bool add(string username,string password,int id);
}instance;
bool CLogin::add(string username,string password,int id)
{
for(int dynamicId=1 ; dynamicId<=id ; dynamicId++)
{
if(index[dynamicId]==username)
{
return false;
}
}
index[id+1]=username;
account[index[id+1]] = password;
return true;
}
void createAccount(int& numberOfAccounts)
{
string tempName, tempPass;
for(;
{
system("CLS");
cout<<"\n\tEnter username: ";getline(cin,tempName);
cout<<"\tEnter password: ";getline(cin,tempPass);
if(instance.add(tempName,tempPass,numberOfAccounts))
{
numberOfAccounts++;
return;
}
system("CLS");
cout<<"\n\tAccount already exists!";
Sleep(2000);
}
}
void displayAccounts(int numberOfAccounts)
{
system("CLS");
cout<<endl;
for(int i=1 ; i<=numberOfAccounts ; i++)
{
cout<<"\tAccout "<<i<<": "<<instance.index[i]<<endl;
}
cout<<"\t";
system("PAUSE");
}
void removeAccount(int toRemove, int& accounts)
{
for( ; toRemove < accounts ; toRemove++)
{
instance.index[toRemove]=instance.index[toRemove+1];
instance.account[instance.index[toRemove]]=instance.account[instance.index[toRemove+1]];
}
instance.index.erase(accounts);
instance.account.erase(instance.index[accounts]);
}
void deleteAccount(int& id)
{
string names;
if(id == 0)
{
cout<<"\n\tNo accounts to delete!";
Sleep(2500);
return;
}
names = "";
names += instance.index[1];
for(int i=2 ; i < id ; i++)
{
names += "|";
names += instance.index[i];
}
if(id>=2)
{
names += "|";
names+=instance.index[id];
}
cout<<endl;
removeAccount(drawMenu("Select an account to delete",names,1),id);
id--;
return;
}
int main(void)
{
int numberOfAccounts = 0;
for(;
{
system("CLS");
cout<<endl;
switch(drawMenu("Loging Server By TheUberFail","Create Account|Display Accounts|Delete account|Exit",1))
{
case 1: createAccount(numberOfAccounts);break;
case 2: displayAccounts(numberOfAccounts);break;
case 3: deleteAccount(numberOfAccounts);break;
case 4: return EXIT_SUCCESS;
}
}
}
Copyright © 2024, NextGenUpdate.
All Rights Reserved.