Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <cctype>
- #include <string>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- struct Account{
- char id[1000];
- char firstname[1000];
- char middlename[1000];
- char lastname[1000];
- char username[1000];
- char password[1000];
- char mobilenumber[1000];
- };
- //Global
- int token = 0;
- int index = 0;
- Account person[1000];
- //Functions
- int searchusername();
- void signedinmenu();
- void signin();
- void signup();
- void accountmenu();
- void magicsquare();
- void captcha();
- int main(){
- accountmenu();
- }
- int searchusername(){
- char searchusername[1000];
- cin>>searchusername;
- for(int i = 0; i<1000; i++){
- if(strcmp(searchusername, person[i].username) == 0){
- index = i;
- return 0;
- }
- }
- cout<<endl<<"Username not found";
- return 1;
- }
- void signedinmenu(){ //Signed Into Account Function
- while(true){
- system("cls");
- int choice;
- cout<<endl<<"[1] Show Profile";
- cout<<endl<<"[2] Magic Square Minigame";
- cout<<endl<<"[3] Back";
- cout<<endl<<"Choice: ";
- cin>>choice;
- switch(choice){
- case 1:
- cout<<endl<<"ID: ";
- cout<<person[index].id;
- cout<<endl<<"First Name: ";
- cout<<person[index].firstname;
- cout<<endl<<"Middle Name: ";
- cout<<person[index].middlename;
- cout<<endl<<"Last Name: ";
- cout<<person[index].lastname;
- cout<<endl<<"Username: ";
- cout<<person[index].username;
- cout<<endl<<"Password: ";
- for(int i = 0; i < strlen(person[index].password); i++){
- cout<<"*";
- }
- cout<<endl<<"Press enter to continue...";
- cin.ignore(1000, '\n');
- cin.ignore(1000, '\n');
- break;
- case 2:
- magicsquare();
- break;
- case 3:
- return;
- }
- }
- }
- void signin(){ //Sign into Account Function
- string inputpassword;
- int loginAttempt = 5;
- system("cls");
- cout<<endl<<"SIGN-IN";
- while(true){
- cout<<endl<<"Username: ";
- if(searchusername() == 0)
- break;
- }
- while(true){
- cout<<endl<<"Password: ";
- cin.ignore(1000, '\n');
- cin>>inputpassword;
- if(inputpassword.compare(person[index].password) == 0)
- break;
- else
- loginAttempt--;
- if(loginAttempt==0){
- accountmenu();
- }
- }
- captcha();
- cout<<endl<<"Login Successful";
- signedinmenu();
- }
- void signup(){ //Sign-up Function
- string cnfrmpassword;
- int passreqsmet = 0;
- system("cls");
- cout<<endl<<"SIGN-UP";
- cout<<endl<<"ID: ";
- cin.ignore(1000, '\n');
- cin>>person[token].id;
- cout<<endl<<"First Name: ";
- cin.ignore(1000, '\n');
- cin>>person[token].firstname;
- cout<<endl<<"Middle Name: ";
- cin.ignore(1000, '\n');
- cin>>person[token].middlename;
- cout<<endl<<"Last Name: ";
- cin.ignore(1000, '\n');
- cin>>person[token].lastname;
- person[token].firstname[0] = toupper(person[token].firstname[0]);
- person[token].middlename[0] = toupper(person[token].middlename[0]);
- person[token].lastname[0] = toupper(person[token].lastname[0]);
- strncat(person[token].username, person[token].firstname, 1);
- strncat(person[token].username, person[token].middlename, 1);
- strcat(person[token].username, person[token].lastname);
- cout<<endl<<"Username: ";
- cout<<person[token].username;
- cin.ignore(1000, '\n');
- while (true) {
- int req1 = 0;
- int req2 = 0;
- int req3 = 0;
- int req4 = 0;
- int req5 = 0;
- person[token].password[0]= '\0';
- cout << endl << "Password must have the following criteria: 1 uppercase, 1 lowercase, 1 digit, 1 special character, and a minimum length of 8.";
- cout << endl << "Password: ";
- cin.getline(person[token].password, sizeof(person[token].password));
- if (strlen(person[token].password) >= 8) {
- req1 = 1;
- }
- for (int i = 0; i < strlen(person[token].password); i++) {
- if (isupper(person[token].password[i])) {
- req2 = 1;
- break;
- }
- }
- for (int i = 0; i < strlen(person[token].password); i++) {
- if (islower(person[token].password[i])) {
- req3 = 1;
- break;
- }
- }
- for (int i = 0; i < strlen(person[token].password); i++) {
- if (isdigit(person[token].password[i])) {
- req4 = 1;
- break;
- }
- }
- for (int i = 0; i < strlen(person[token].password); i++) {
- if (ispunct(person[token].password[i])) {
- req5 = 1;
- break;
- }
- }
- if (req1 == 1 && req2 == 1 && req3 == 1 && req4 == 1 && req5 == 1) {
- break;
- } else {
- cout << "\nPassword does not meet the criteria. Please try again." << endl;
- continue;
- }
- }
- while(true){
- cout<<endl<<"Confirm Password: ";
- cin>>cnfrmpassword;
- if(cnfrmpassword==person[token].password){
- cout << "\nPassword created successfully.";
- break;
- }
- else{
- cout<<endl<<"Incorrect Password";
- continue;
- }
- }
- while(true){
- cout<<endl<<"Mobile No.: ";
- cin>>person[token].mobilenumber;
- if(strlen(person[token].mobilenumber)!=11){
- cout<<endl<<"Mobile Number must be exactly 11 digits";
- continue;
- }
- break;
- }
- cout<<endl<<"Account created successfully.";
- token++;
- }
- void accountmenu(){ //Main Menu
- int choice;
- system("cls");
- while(true){
- cout<<endl<<"ACCOUNT MENU";
- cout<<endl<<"[1] Sign-in";
- cout<<endl<<"[2] Sign-up";
- cout<<endl<<"[3] Exit";
- cout<<endl<<"Choice: ";
- cin>>choice;
- switch(choice){
- case 1:
- signin();
- continue;
- case 2:
- signup();
- continue;
- case 3:
- return;
- }
- }
- }
- void magicsquare(){ //Magic Square
- int magicsquare [9];
- cout<<endl;
- cout<<endl<<" Magic Square";
- cout<<endl<<"| 1 | 2 | 3 |";
- cout<<endl<<"| 4 | 5 | 6 |";
- cout<<endl<<"| 7 | 8 | 9 |";
- cout<<endl<<"Enter number from 0 to 9";
- for(int i=0; i<9; i++){
- cout<<endl<<"Enter number for "<<i+1<<": ";
- cin>>magicsquare[i];
- }
- cout<<endl<<" | "<<magicsquare[0]<<" | "<<magicsquare[1]<<" | "<<magicsquare[2]<<" |";
- cout<<endl<<" | "<<magicsquare[3]<<" | "<<magicsquare[4]<<" | "<<magicsquare[5]<<" |";
- cout<<endl<<" | "<<magicsquare[6]<<" | "<<magicsquare[7]<<" | "<<magicsquare[8]<<" |";
- /*
- | 0 | 1 | 2 |
- | 3 | 4 | 5 |
- | 6 | 7 | 8 |
- */
- int sum1, sum2, sum3, sum4, sum5, sum6, sum7, sum8;
- sum1 = magicsquare[0] + magicsquare[1] + magicsquare[2];
- sum2 = magicsquare[3] + magicsquare[4] + magicsquare[5];
- sum3 = magicsquare[6] + magicsquare[7] + magicsquare[8];
- sum4 = magicsquare[0] + magicsquare[4] + magicsquare[8];
- sum5 = magicsquare[6] + magicsquare[4] + magicsquare[2];
- sum6 = magicsquare[2] + magicsquare[5] + magicsquare[8];
- sum7 = magicsquare[1] + magicsquare[4] + magicsquare[7];
- sum8 = magicsquare[0] + magicsquare[3] + magicsquare[6];
- if(sum1 == sum2 && sum2 == sum3 && sum3 == sum4 && sum4 == sum5 && sum5 == sum6 && sum6 == sum7 && sum7 == sum8){
- cout<<endl<<"It is a magic square";
- cout<<endl<<"Press enter to proceed...";
- cin.ignore(1000, '\n');
- cin.ignore(1000, '\n');
- return;
- }
- else
- cout<<endl<<"It is not a magic square";
- cout<<endl<<"Press enter to proceed...";
- cin.ignore(1000, '\n');
- cin.ignore(1000, '\n');
- return;
- }
- void captcha(){
- int attempt=5;
- while(true){
- const string characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- int charactersLength = characters.length();
- int captchaLength = 6;
- string randomstring;
- string usercaptcha;
- srand(static_cast<unsigned int>(time(nullptr)));
- for(int i= 0; i<captchaLength; i++){
- randomstring += characters[rand() % charactersLength];
- }
- cout <<endl << "Captcha: " << randomstring << endl;
- cout<<endl<<"Enter Captcha: ";
- cin>>usercaptcha;
- if(usercaptcha==randomstring)
- break;
- attempt--;
- if(attempt==0){
- cout<<endl<<"Too many attempts...";
- accountmenu();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement