#include <stdio.h>
#include <stdlib.h>
#include <time.h>
-#include <stdbool.h>
#include <string.h>
#include <ctype.h>
+#include <unistd.h>
#include "wordblox.h"
#include "constantstrings.h"
char ch = getchar ();
}
-/* set the password for the puzzle */
-void do_set_password (Puzzle *p)
+/* set the solution password for the puzzle */
+void do_set_solution_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);
+ set_solution_password (p, "\0");
+ printf (SOLUTION_PASSWORD_RESET);
char ch = getchar ();
}
/* set the password */
else
{
- char *passwd = strtok (password, "\n");
-
- set_puzzle_password (p, (const char* )passwd);
+ set_solution_password (p, (const char* )password);
+ printf (PASSWORD_SET);
+ char ch = getchar ();
+ }
+}
+/* set the master (editing) password for the puzzle */
+void do_set_master_password (Puzzle *p)
+{
+ char* password;
+ password = getpass (INPUT_PASSWORD);
+ /* if empty reset the password to nothing */
+ if (strlen(password) == 0)
+ {
+ set_master_password (p, "\0");
+ printf (MASTER_PASSWORD_RESET);
+ char ch = getchar ();
+ }
+ /* set the password */
+ else
+ {
+ set_master_password (p, (const char* )password);
printf (PASSWORD_SET);
char ch = getchar ();
}
index = get_num ();
printf (INPUT_CLUE);
fgets (clue, MAX_CLUE_LENGTH, stdin);
+ if (strlen (clue) == 1)
+ return;
char* cl = strtok (clue, "\n");
bool res;
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, 15, 50);
printf (INPUT_CHOICE);
int ch = get_num ();
switch (ch)
printf ("%s\n",FILE_SAVED);
ch = getchar ();
break;
- case 10: do_set_password (p);
+ case 10: do_set_master_password (p);
break;
- case 11: do_reset_puzzle (p);
+ case 11: do_set_solution_password (p);
break;
- case 12: do_export_puzzle (p);
+ case 12: do_reset_puzzle (p);
break;
- case 13: do_export_clues (p);
+ case 13: do_export_puzzle (p);
break;
- case 14: loop = ! do_confirm_exit ();
+ case 14: do_export_clues (p);
+ break;
+ case 15: loop = ! do_confirm_exit ();
break;
}
}
p = load_puzzle (filename);
- if (strcmp (p.hashed_password, "\0") != 0)
+ if (strcmp (p.hashed_master_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_master_password (&p, (const char*) passwd))
puzzle_editor_loop (&p, filename);
else
{