#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "sha512.h" #define WAIT_TICK 10000 using namespace std; WINDOW *wnd; string pw=""; char pwchar='*'; bool randomchar=true; bool exit_requested=false; bool changepassword=false; bool softlock=false; int pwfieldlength=40; int LINES; int COLS; vector quitmsgs; vector wrongmsgs; string pwpath=""; string pwhash="3c9909afec25354d551dae21590bb26e38d53f2173b8d3dc3eee4c047e7ab1c1eb8b85103e3be7ba613b31bb5c9c36214dc9f14a42fd7a2fdb84856bca5c44c2"; int init() { srand(time(NULL)); fstream f(pwpath, ios::in); if (f.good()) { getline(f, pwhash); if (pwhash.length()<20) { cerr << "Error: passwd file not correctly formatted." << endl; exit(1); } } else { cerr << "Error while loading password file." << endl; exit(1); } f.close(); initscr(); wnd=newwin(0,0,0,0); getmaxyx(wnd,LINES,COLS); noecho(); clear(); keypad(wnd, true); //curs_set(0); start_color(); init_pair(1,COLOR_WHITE, COLOR_BLACK); init_pair(2,COLOR_WHITE, COLOR_BLUE); init_pair(3,COLOR_RED, COLOR_BLACK); bkgd(COLOR_PAIR(1)); string enterpw="Enter password:"; for (int i=0; ipw_dir; pwpath=homedir + "/.xlockpw"; if (argc<=1) { init(); run(); } else if (argc==2) { if (string(argv[1])=="chpw") { changepassword=true; fstream f1(pwpath, ios::in); if (f1.good()) { init(); run(); } f1.close(); string p1; string p2; /* cout << endl << "Enter new password: "; getline(cin,p1); cout << endl << "Repeat password: "; getline(cin,p2); */ p1=readPw("Enter a Password:"); p2=readPw("Repeat Password:"); if (p1==p2) { ofstream f; f.open(pwpath, std::ofstream::out | std::ofstream::trunc); if (f.good()) { f << sha512(p1); } else { cerr << "Error while loading password file." << endl; cerr << "170" << endl; exit(1); } chmod((char *)pwpath.c_str(),0600); f.close(); cout << endl << "Password updated." << endl; } else { cerr << "Passwords do not match"; } } else if (string(argv[1])=="soft") { softlock=true; init(); run(); } /*else if (string(argv[1])=="read") { cout << readPw("Enter Password:") << endl; }*/ else { cerr << "unknown argument." << endl; } } else { cerr << "too many arguments" << endl; } }