X-Git-Url: https://harishankar.org/repos/?p=wordblah.git;a=blobdiff_plain;f=wordblox.c;h=fae8b838109ee9d72c7f1b15b463fc5a7f03b5fb;hp=61de6b6991fba50c54baa4d86f48110e6ed9ad7e;hb=3d73a89d86191634ac382e0772708389686b8dde;hpb=48a65b2e455c24d2482fd9098c918935714a198f diff --git a/wordblox.c b/wordblox.c index 61de6b6..fae8b83 100644 --- a/wordblox.c +++ b/wordblox.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "wordblox.h" #include "constantstrings.h" @@ -73,11 +74,10 @@ void do_reset_puzzle (Puzzle *p) /* set the password for the puzzle */ void do_set_password (Puzzle *p) { - printf (INPUT_PASSWORD); - char password[256]; - fgets (password, 256, stdin); + char* password; + password = getpass (INPUT_PASSWORD); /* if empty reset the password to nothing */ - if (strlen (password) == 1) + if (strlen(password) == 0) { set_puzzle_password (p, "\0"); printf (PASSWORD_RESET); @@ -86,9 +86,7 @@ void do_set_password (Puzzle *p) /* set the password */ else { - char *passwd = strtok (password, "\n"); - - set_puzzle_password (p, (const char* )passwd); + set_puzzle_password (p, (const char* )password); printf (PASSWORD_SET); char ch = getchar (); } @@ -257,7 +255,9 @@ void puzzle_editor_loop (Puzzle *p, const char *filename) bool loop = true; while (loop) { - print_menu (WHITE, BLUE, PUZZLE_MENU_TITLE, PUZZLE_EDIT_MENU, 14, 50); + char puzzle_title[60]; + sprintf (puzzle_title, "%s - %s", PUZZLE_MENU_TITLE, filename); + print_menu (WHITE, BLUE, puzzle_title, PUZZLE_EDIT_MENU, 14, 50); printf (INPUT_CHOICE); int ch = get_num (); switch (ch) @@ -320,14 +320,12 @@ void do_open_puzzle (const char *filename) if (strcmp (p.hashed_password, "\0") != 0) { - char passwd[256]; - printf (INPUT_PASSWORD); - fgets (passwd, 256, stdin); - if (strlen (passwd) == 1) + char *passwd; + passwd = getpass (INPUT_PASSWORD); + if (strlen (passwd) == 0) return; - char *pwd = strtok (passwd, "\n"); - - if (verify_password (&p, (const char*) pwd)) + + if (verify_password (&p, (const char*) passwd)) puzzle_editor_loop (&p, filename); else {