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;
}
| |