Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<conio.h>
- using namespace std;
- struct user
- {
- string name;
- string birth;
- string pass;
- };
- int loginMenu();
- int loginPage();
- void activeMenu();
- void checkMenu(int x);
- void registerOption();
- bool checkLogin(string username,string password);
- int main()
- {
- checkMenu(loginMenu());
- }
- int loginMenu()
- {
- system("cls");
- int option;
- cout<<"(1) Login"<<endl
- <<"(2) Register"<<endl
- <<"(3) Exit"<<endl
- <<"\nOption: ";
- cin >>option;
- return option;
- }
- void checkMenu(int x)
- {
- if(x == 1)
- {
- loginPage();
- }
- else if(x == 2)
- registerOption();
- else if(x == 3)
- {
- exit(0);
- }
- else
- {
- cout<<"Invalid Option";
- system("pause");
- checkMenu(loginMenu());
- }
- }
- void registerOption()
- {
- system("cls");
- ofstream databaseName;
- databaseName.open("databaseName.dat",std::ios_base::app);
- ofstream databaseBirth;
- databaseBirth.open("databaseBirth.dat",std::ios_base::app);
- ofstream databasePass;
- databasePass.open("databasePass.dat",std::ios_base::app);
- user User;
- cout<<"Username: ";
- cin.ignore();
- getline(cin,User.name);
- databaseName<<User.name<<endl;
- cout<<"Birthday: ";
- getline(cin,User.birth);
- databaseBirth<<User.birth<<endl;
- cout<<"Password: ";
- getline(cin,User.pass);
- databasePass<<User.pass<<endl;
- databaseName.close();
- databaseBirth.close();
- databasePass.close();
- cout<<User.name<<" "<<User.birth<<"\nRecord Saved"<<endl;
- system("pause");
- checkMenu(loginMenu());
- }
- int loginPage()
- {
- system("cls");
- char option;
- string username, password;
- cout<<"Enter Username: ";
- cin.ignore();
- getline(cin,username);
- cout<<"Password: ";
- char PIN[20];
- int i = 0;
- while (1)
- {
- PIN[i] = _getch(); //getch() - get character without echo
- if (PIN[i] == 13) // enter key =13
- {
- PIN[i] = '\0'; //='terminating the C-String variable
- break;
- }
- else if (PIN[i] == 8 && i > 0)
- {
- cout << "\b \b";
- i--;
- }
- else if (PIN[i] == 8) // use this code when backspace issue
- {
- cout << " \b";
- }
- else
- {
- cout << "*";
- i++;
- } //13 is ASCII value for Enter
- }
- if (checkLogin(username, PIN))
- activeMenu();
- else
- {
- do
- {
- system("cls");
- cout<<"Invalid Username or Password"<<endl
- <<"Try again? [y/n]: ";
- cin >>option;
- if(option == 'y'||option == 'Y')
- loginPage();
- else if(option == 'n'||option == 'N')
- checkMenu(loginMenu());
- else
- {
- cout<<"Invalid option"<<endl;
- system("pause");
- }
- }while(option != 'n' || option != 'N' || option != 'y' || option != 'Y');
- }
- }
- bool checkLogin(string username,string password)
- {
- ifstream databaseName;
- databaseName.open("databaseName.dat");
- ifstream databasePass;
- databasePass.open("databasePass.dat");
- string line, pass;
- int value = 0;
- while(getline(databaseName,line) && getline(databasePass,pass))
- {
- if(line == username && pass == password)
- value = 1;
- }
- if(value == 1)
- return true;
- else
- return false;
- databaseName.close();
- databasePass.close();
- }
- void activeMenu()
- {
- system("cls");
- int option;
- cout<<"(1) Profile"<<endl
- <<"(2) News Feed"<<endl
- <<"(3) Post"<<endl
- <<"(4) Search"<<endl
- <<"(5) Special"<<endl
- <<"(6) Logout"<<endl
- <<"\nOption: ";
- cin >>option;
- if(option == 1)
- cout<<"Hello";
- else if(option == 2)
- cout<<"Hello";
- else if(option == 3)
- cout<<"Hello";
- else if(option == 4)
- cout<<"Hello";
- else if(option == 5)
- cout<<"Hello";
- else if(option == 6)
- checkMenu(loginMenu());
- else
- cout<<"Hello";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement