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