How would you suggest I merge these programs?

So i have three ncurses programs (each one has a main, a cpp and a few header files and text files) and one oop (with text files and one main).

This is the idea of how the finished ONE program should look:

choose option:
1
2
3

if option 1 is chose then 'x' ncurses program is shown
if option 2 then 'y' ncurses program is shown
and so on.

How would you suggest I merge these programs?

(codes in reply)
forgotpass.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <iostream>
#include <curses.h> 
#include <assert.h>   
#include "coord.h"  
#include <string> 
#include <fstream>
using namespace std;
fstream pass;
char c;  
string newpassword; 
string confpassword;
int movement;
enum movement {ebox,pbox,obox,cbox};
coord frontcursorloc[4]={coord(22,4),coord(22,7),coord(20,13),coord(38,13)}; 

void cycletab(){
    int i=movement++%4;
    move(frontcursorloc[i].my,frontcursorloc[i].mx);
    cout << frontcursorloc[i].my;
} 

void nxtbox(){
noecho();
keypad(stdscr, TRUE);  
cycletab();

while (int c=getch()){
int tab=(movement%4==0)?3:movement%4-1;
assert(tab >= 0 && tab < 4);
switch (c){ 

	case 10:
  case -53:
		//if (c==' '){ 
			if(tab==obox)return;
			if(tab==cbox){
   	 	    	newpassword="<no input>"; 
					confpassword="<no input>";
			return;
			}
      break;
		//}

	case KEY_RIGHT:
		cycletab();
		break;
 
	default:
    switch(tab){ 
      case ebox:
      if(int(c)!=127)printw("%c",'*');
       newpassword.append(1,c);
      break;
			case pbox:
       if(int(c)!=127)printw("%c",'*');
       confpassword.append(1,c);
      break;
        }

}
}
}

 
void displayresetpass(){  
	initscr(); 
	int x=0, y=1, w=60, h=15;
	WINDOW *win = newwin(h,w,y,x);
	refresh();
	move(1, 27);
	attron(A_BOLD);
	printw("RESET PASS");
	box(win, 0, 0);
	wrefresh(win);
}

void displaynewpass(){
	mvprintw(4,4,"new pass");
	WINDOW* ebox = newwin(3, 35, 3, 20);
	refresh();
	box(ebox, 0, 0); 
	wrefresh(ebox);
}

void displayconfPassword(){
	mvprintw(7, 4, "confirm new pass");
	WINDOW* pbox = newwin(3, 35, 6, 20);
	refresh();
	box(pbox, 0, 0);
	wrefresh(pbox);
}

void displayOkCancel(){
	WINDOW*  obox = newwin(3, 10, 12, 14);
	refresh();
	box(obox, 0, 0);
	attron(A_BOLD);
	mvwprintw(obox, 1, 1, "   OK");
	attron(A_BOLD);
	wrefresh(obox);


	WINDOW* cbox = newwin(3, 10, 12, 34);
	refresh();
	box(cbox, 0, 0);
	attron(A_BOLD); 
	mvwprintw(cbox,1, 1, " CANCEL");
	attron(A_BOLD);
	wrefresh(cbox);
}  

void comparepass(string newpassword, string confpassword){
	    if (newpassword != confpassword) 
        cout << "error: passwords do not match";
			else if (newpassword == confpassword) {
      	cout << "passwords match. pass has been reset.";
				pass.open("newpass.txt");
				pass<<confpassword;
				pass.close();
			}
			else
			cout<<"error";
}


int main(){
initscr();
noecho();
cbreak();
	displayresetpass();
	displaynewpass(); 
	displayconfPassword(); 
	displayOkCancel();
	nxtbox();
	getch();
	endwin();
cout << "\n\nnew-passw received was : " << newpassword << endl;
cout << "confirmed-passw obtained was : " << confpassword << endl;
comparepass(newpassword, confpassword);
	return 0;
}
oop.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <iostream>
using namespace std;
#include <fstream>
#include <string>
#include <limits.h>

class user {
	public:
		char choice1;		
		string newpass;
		fstream usernames;
		fstream pswd;
		fstream npswd;
		fstream rnusernames;
		fstream rnpass;
		fstream rmaide;
};

class olduser : public user {
	private:
	string temp;
	string temp1;
	string temp2;
	string username;
	string userpass;
	string newuserpass;
	string loginyn;
	string mynewpass;

	public:
		int checkusername(){
		usernames.open("names.txt");
		cout << "\nplease enter your username   ";
		cin >> username; 
		while ((usernames >> temp)) { 
			if (temp.compare(username) == 0) {
				usernames.close();
				return 1;
			}
		}
		usernames.close();
		return 0;
		}
		
		int checkpassword(){
		cout<<"please enter your password   ";
		cin>>userpass;
		pswd.open("pass.txt");
			while (pswd >> temp1) { 
				if (temp1.compare(userpass) == 0){
					cout<<"\n[ "<<username<<" ] having password [ "<<userpass<<" ] has been found in the database.\n\n";
					pswd.close();
					return 1;
				}
			}
		pswd.close();
		return 0;
		}
		int checknewpassword(){
		cout<<"please enter your password   ";
		cin>>newuserpass;
		npswd.open("newpass.txt");
			while (npswd >> temp2) { 
				if (temp2.compare(newuserpass) == 0){
					cout<<"Congratulations!!! You have successfully logged in with your new password.";
					npswd.close();
					return 1;
				}
				else{
					cout<<"ACCESS DENIED";
				}
			}
		npswd.close();
		return 0;
		}
		
		int creatnewpass(){
		cout<<"Password: ";
		cin>>mynewpass;
		npswd.open("newpass.txt");
		npswd<<mynewpass;
		npswd.close();
			cout<<"\nLogin now? (y/n) ";
		cin>>loginyn;
			if(loginyn=="y"){
				cout<<"\n        [LOGIN PROCESS STARTING...]\n";
				checkusername();
				checknewpassword();
			}
		return 0;
		}
		private:
};

class newuser :  public user {
	private:
	string nusername;
	string rpass;
	string maiden;

	public:
		void askusername(){
			cout<<"\nUsername: ";
			cin>>nusername;
			rnusernames.open("newnames.txt");
			rnusernames<<nusername;
			rnusernames.close();
		}

		void askuserpass(){
			cout<<"Password: ";
			cin>>rpass;
			rnpass.open("newpass.txt");
			rnpass<<rpass;
			rnpass.close();
		}

		void askMMN(){
			cout<<"Mother's maiden name: ";
			cin>>maiden;
			rmaide.open("maidennames.txt");
			rmaide<<maiden;
			rmaide.close();
		}
};

int main() {
newuser r;
user u;   
olduser verify; 
int attempts, success;
cout<<"\nAre you a new user? (y/n) ";
cin>>u.choice1;
	if (u.choice1 == 'n'){
		for (attempts = 1; attempts < 4; attempts++){
			success = verify.checkusername();
				if (success == 1) { 
					break; 
				}
			}
		if (success == 0){
			cout<<"\nACCESS DENIED\n";
			cin.ignore();
			abort();
		}
		verify.checkpassword();
		cout<<"would you like to create a new password? (y/n) ";
		cin>>u.newpass;
			if (u.newpass=="y"){
				verify.creatnewpass();
			}
			else if (u.newpass=="n"){
				cin.ignore();
				abort();
			}
	}
	else if (u.choice1 == 'y'){
		r.askusername();
		r.askuserpass();
		r.askMMN();
		cin.ignore();
		abort();
	}
	else {
		cout<<"Error";
	}
return 0;
}
register.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include <iostream>
#include <curses.h> 
#include <fstream>
#include <assert.h> 
#include "coord.h"  
using namespace std; 
fstream usernames;
fstream mmn;
fstream pass;
char c;  
string newpassword;
string username;
string MMN; 
string confpassword;
int movement;
enum movement {abox,cbox,dbox,ebox,fbox,gbox};
coord frontcursorloc[6]={coord(26,4),coord(26,7),coord(26,10),coord(26,13),coord(22,21),coord(43,21)}; 
/*coord backcursorlocname[6]={coord(26,4),coord(43,21),coord(22,21),coord(26,13),coord(26,10),coord(26,7)};*/

void cycletab(){
    int i=movement++%6;
    move(frontcursorloc[i].my,frontcursorloc[i].mx);
    cout << frontcursorloc[i].my;
} 
 
void nxtbox(){
noecho();
keypad(stdscr, TRUE);  
cycletab();

while (int c=getch()){
int tab=(movement%6==0)?5:movement%6-1;
assert(tab >= 0 && tab < 6);
switch (c){

	case 10:
  case -53:
		//if (c==' '){ 
			if(tab==fbox)return; 
			if(tab==gbox){
   	 	username="<no input>";
			MMN="<no input>";
    	newpassword="<no input>"; 
			confpassword="<no input>";
			return;
			}
      break;
		//}

	case KEY_RIGHT:
		cycletab();
		break;
 
	default:
    switch(tab){ 
      case abox:
      if(int(c)!=127)printw("%c",c);
       username.append(1,c);
			usernames.open("newnames.txt");
			usernames<<username;
			usernames.close();
      break;
			case cbox:
       if(int(c)!=127)printw("%c",c);
       MMN.append(1,c);
			 mmn.open("maidennames.txt");
			 mmn<<MMN;
			 mmn.close();
      break;
			case dbox:
       if(int(c)!=127)printw("%c",'*');
       newpassword.append(1,c);
      break;
			case ebox:
       if(int(c)!=127)printw("%c",'*');
       confpassword.append(1,c);
      break;
        }

}
}
}



void name(){
	mvprintw(4,4,"Username");  

	WINDOW* abox = newwin(3, 36, 3, 25);
	refresh();
	box(abox, 0, 0);
	wrefresh(abox);
}
 
void MMName(){
	mvprintw(7,4,"Mother's maiden name");

	WINDOW* cbox = newwin(3, 36, 6, 25);
	refresh();
	box(cbox, 0, 0);
	wrefresh(cbox);
}

void registration(){ 
int x=0, y=1, w=67, h=25;

	WINDOW *win = newwin(h,w,y,x);

	refresh();
	move(1, 25);
	
	attron(A_BOLD);
	printw("REGISTRATION");
	attron(A_BOLD);

	box(win, 0, 0); 
	wrefresh(win);
} 

void displayPassword(){
	mvprintw(10, 4, "New Password");

	WINDOW* dbox = newwin(3, 36, 9, 25);
	refresh();
	box(dbox, 0, 0);
	wrefresh(dbox);
}
 
void displayPassword2(){
	mvprintw(13, 4, "Confirm New Password");
 
	WINDOW* ebox = newwin(3, 36, 12, 25);
	refresh();
	box(ebox, 0, 0);
	wrefresh(ebox);
}

void displayOkCancel(){
	WINDOW* fbox = newwin(3, 10, 20, 18);
	refresh();
	box(fbox, 0, 0);
	mvwprintw(fbox, 1, 1, "   Ok");
	wrefresh(fbox);


	WINDOW* gbox = newwin(3, 10, 20, 39);
	refresh();
	box(gbox, 0, 0);
	mvwprintw(gbox,1, 1, " Cancel");
	wrefresh(gbox);
}  

void comparepass(string newpassword, string confpassword){
	    if (newpassword != confpassword) 
        cout << "error: passwords do not match. unable to register.";
			else if (newpassword == confpassword) {
      	cout << "passwords match. you are now a registered user.";
				pass.open("newpass.txt");
				pass<<confpassword;
				pass.close();
			}
			else
			cout<<"error";
}

int main(){
initscr();
noecho();
cbreak();


    registration();
    name();
    MMName();
    displayPassword();
		displayPassword2();
		displayOkCancel();
		nxtbox();
		//cycletab();
	getch();

	//deallocate memory and ends ncurses
	endwin();
cout << "\n\nusername received was : " << username << endl;
cout << "MMN received was : " << MMN << endl;
cout << "passw obtained was : " << confpassword << endl;
comparepass(newpassword, confpassword);
	return 0;
}
login.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include <iostream>
#include <fstream>
#include <curses.h>
#include <assert.h> 
#include "coord.h"  
#include <string>
using namespace std;
fstream uname, upass;
char c;  
string password; 
string temp1, temp2;
string username;
int movement;
enum movement {ebox,pbox,obox,cbox};
coord frontcursorloc[4]={coord(22,4),coord(22,7),coord(20,13),coord(38,13)}; 

void cycletab(){
    int i=movement++%4;
    move(frontcursorloc[i].my,frontcursorloc[i].mx);
    cout << frontcursorloc[i].my;
} 

void nxtbox(){
noecho();
keypad(stdscr, TRUE);  
cycletab();

while (int c=getch()){
int tab=(movement%4==0)?3:movement%4-1;
assert(tab >= 0 && tab < 4);
switch (c){ 

	case 10:
  case -53:
		//if (c==' '){ 
			if(tab==obox)return;
			if(tab==cbox){
   	 	username="<no input>";
    	password="<no input>"; 
			break;
			}
      break;
		//}

	case KEY_RIGHT:
		cycletab();
		break;

	/*case KEY_LEFT:
			backcycletab1();
	break;*/
 
	default:
    switch(tab){ 
      case ebox:
      if(int(c)!=127)printw("%c",c);
       username.append(1,c);
      break;
			case pbox:
       if(int(c)!=127)printw("%c",'*');
       password.append(1,c);
      break;
        }

}
}
}

 
void displayLogin(){  
	initscr();
	int x=0, y=1, w=60, h=15;
	WINDOW *win = newwin(h,w,y,x);
	refresh();
	move(1, 27);
	attron(A_BOLD);
	printw("LOGIN");
	box(win, 0, 0);
	wrefresh(win);
}

void displayEmail(){
	mvprintw(4,4,"Username");
	WINDOW* ebox = newwin(3, 35, 3, 20);
	refresh();
	box(ebox, 0, 0); 
	wrefresh(ebox);
}

void displayPassword(){
	mvprintw(7, 4, "Password");
	WINDOW* pbox = newwin(3, 35, 6, 20);
	refresh();
	box(pbox, 0, 0);
	wrefresh(pbox);
}

void displayOkCancel(){
	WINDOW*  obox = newwin(3, 10, 12, 14);
	refresh();
	box(obox, 0, 0);
	attron(A_BOLD);
	mvwprintw(obox, 1, 1, "   OK");
	attron(A_BOLD);
	wrefresh(obox);


	WINDOW* cbox = newwin(3, 10, 12, 34);
	refresh();
	box(cbox, 0, 0);
	attron(A_BOLD); 
	mvwprintw(cbox,1, 1, " CANCEL");
	attron(A_BOLD);
	wrefresh(cbox);
}  
   
void resetpass(){
attron(A_UNDERLINE); 
mvprintw(10,21,"Reset password...");
attron(A_UNDERLINE);
} 

int verifyusername(){ 
		uname.open("names.txt"); 
			while (uname >> temp1) { 
				if (temp1.compare(username) == 0){
					cout<<"\n[ "<<username<<" ] has been found in the database.";	
					uname.close();
					return 1;
				}
				else{ 
					cout<<"\nACCESS DENIED [wrong username]";
					break;
				}
			}
		uname.close();
return 0; 
} 

int verifypass(){ 
			upass.open("pass.txt");
			while (upass >> temp2) { 
				if (temp2.compare(password) == 0){
					cout<<"\npass found.";
					upass.close();
					return 1;
				}
				else{
					cout<<"\nACCESS DENIED [wrong pass]";
					break; 
				} 
			}
			upass.close();
return 0; 
} 
  
int verifyboth(){
uname.open("names.txt"); 
upass.open("pass.txt");
	while ((upass >> temp2)&&(uname>>temp1)) {
		if (temp1.compare(username) ==0 && temp2.compare		(password) ==0){
			cout<<"\n\nyou can now login!!";
			uname.close();
			upass.close();
			return 1;
		}
		else {
			cout<<"\n\nyou can not login!!";
		break;
		}
	}
uname.close();
upass.close();
return 0;
}

int main(){
initscr(); 
noecho();
cbreak();
	displayLogin();
	displayEmail();
	displayPassword();
	resetpass();
	displayOkCancel();
	nxtbox();
	getch();
	endwin();
cout << "\n\nusername received was : " << username << endl;
cout << "passw obtained was : " << password << endl;
verifyusername();
verifypass();
verifyboth();
	return 0;
}
Last edited on
Topic archived. No new replies allowed.