Skip to content

Instantly share code, notes, and snippets.

@cindrmon
Last active September 27, 2020 12:31
Show Gist options
  • Save cindrmon/437488aa2a11e53d0c5ef8dc669a82dc to your computer and use it in GitHub Desktop.
Save cindrmon/437488aa2a11e53d0c5ef8dc669a82dc to your computer and use it in GitHub Desktop.
MP1_INFOSEC_LogicBomb
#include<iostream>
#include<string>
using namespace std;
// VARIABLE ALIASES ========================
typedef int CTR;
typedef int LIST_SIZE;
typedef string USER_INPUT;
// ACCOUNT DATA STRUCTURE SCHEMA ===========
struct Account {
string Username;
string Password;
Account* Next;
}*GenesisBlock = NULL, *PlatformBlk, *AccountSet, *Cap = NULL;
// DATA STRUCTURE TESTS ====================
bool LinkedListEmpty() {
if(GenesisBlock==NULL)
return 1;
else
return 0;
}
// DATA STRUCTURE OPERATIONS ===============
// Login a User ============================
void UserLoginCheck(USER_INPUT Username, USER_INPUT Passwd, bool* isLoggedIn){
if(LinkedListEmpty())
cout << "\nThere are no accounts stored.";
else{
PlatformBlk = GenesisBlock;
while(PlatformBlk != NULL && PlatformBlk->Username != Username){
PlatformBlk = PlatformBlk->Next;
}
if(PlatformBlk == NULL){
*isLoggedIn = false;
}
// did not find any matching usernames
else{
cout << "Found Searches:\n";
cout << "\tUsername: " << PlatformBlk->Username << endl;
cout << "\tPassword: " << PlatformBlk->Password << endl << endl;
if(PlatformBlk->Password == Passwd)
*isLoggedIn = true;
// found the matching username, and tests if the password matches
}
}
}
// Login Content Example ===================
void LoginContent(bool* isLoggedIn){
cout << "\n\nWelcome! You have successfully logged in!\n";
cout << "Sorry if there is nothing much to do as of now\n";
cout << "\nPress enter to logout\n> ";
cin.get();
*isLoggedIn = 0;
}
// Print all Existing Users ================
void PrintItems() {
CTR IDX;
if(LinkedListEmpty())
cout << "There are no accounts stored\n";
else {
PlatformBlk = GenesisBlock;
while(PlatformBlk!=NULL){
cout << "Username: " << PlatformBlk->Username << endl;
cout << "Password: " << PlatformBlk->Password << endl << endl;
PlatformBlk = PlatformBlk->Next;
}
}
}
// Sign Up a new user ======================
void UserSignup(USER_INPUT Username, USER_INPUT Password){
Account *InsertAccount;
if(GenesisBlock == NULL){
// Sets username and password into an AccountSet object
InsertAccount = (Account*) malloc(sizeof(Account));
InsertAccount->Username = Username;
InsertAccount->Password = Password;
InsertAccount->Next = NULL;
// Sets it as the Genesis Block/Start of the linked list
GenesisBlock = InsertAccount;
AccountSet = GenesisBlock;
}
else{
InsertAccount = (Account*) malloc(sizeof(Account));
InsertAccount->Username = Username;
InsertAccount->Password = Password;
InsertAccount->Next = NULL;
if(AccountSet == GenesisBlock){
GenesisBlock->Next = InsertAccount;
AccountSet = InsertAccount;
Cap = InsertAccount;
}
else{
AccountSet->Next = InsertAccount;
Cap = InsertAccount;
AccountSet = AccountSet->Next;
}
}
}
// MAIN PROGRAM ============================
int main() {
USER_INPUT username, password;
int choice;
bool isLoggedIn = false;
do{
cout << "Welcome To TAMS!" << endl;
cout << "What do you want to do?" << endl;
cout << "(1) -> Print All Users; (2) -> Sign Up; (3) -> Login; (4) Exit\n\n> ";
cin >> choice;
switch (choice) {
case 1:
PrintItems();
break;
case 2:
cout << "\nWelcome New User!\n";
cout << "Please Enter your credentials:\n";
cout << "Username: ";
cin.get();
getline(cin, username);
cout << "Password: ";
getline(cin, password);
UserSignup(username, password);
cout << "Successfully signed up! You can enter (3) to login.";
break;
case 3:
cout << "\nWelcome Existing User!\n";
cout << "Please Enter your credentials:\n";
cout << "Username: ";
cin.get();
getline(cin, username);
cout << "Password: ";
getline(cin, password);
UserLoginCheck(username, password, &isLoggedIn);
if (!isLoggedIn){
cout << "\n\nInvalid Username or password! Please try again\n\n";
break;
}
else{
LoginContent(&isLoggedIn);
if(!isLoggedIn)
break;
}
default:
cout << "\n\nThank you for using this program, goodbye!\n\n";
}
}while(choice != 4);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment