mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 06:13:03 +01:00
improvements to password entry screen
This commit is contained in:
parent
cf3f6750eb
commit
f405ae8b42
51
src/toxic.c
51
src/toxic.c
@ -82,11 +82,11 @@ struct arg_opts arg_opts;
|
|||||||
struct user_settings *user_settings_ = NULL;
|
struct user_settings *user_settings_ = NULL;
|
||||||
|
|
||||||
#define MIN_PASSWORD_LEN 6
|
#define MIN_PASSWORD_LEN 6
|
||||||
#define MAX_PASSWORD_LEN 256
|
#define MAX_PASSWORD_LEN 64
|
||||||
|
|
||||||
static struct _user_password {
|
static struct _user_password {
|
||||||
bool data_is_encrypted;
|
bool data_is_encrypted;
|
||||||
char pass[MAX_STR_SIZE];
|
char pass[MAX_PASSWORD_LEN + 1];
|
||||||
int len;
|
int len;
|
||||||
} user_password;
|
} user_password;
|
||||||
|
|
||||||
@ -474,8 +474,6 @@ static void load_friendlist(Tox *m)
|
|||||||
/* return length of password on success, 0 on failure */
|
/* return length of password on success, 0 on failure */
|
||||||
static int password_prompt(char *buf, int size)
|
static int password_prompt(char *buf, int size)
|
||||||
{
|
{
|
||||||
printf("> ");
|
|
||||||
|
|
||||||
/* disable terminal echo */
|
/* disable terminal echo */
|
||||||
struct termios oflags, nflags;
|
struct termios oflags, nflags;
|
||||||
tcgetattr(fileno(stdin), &oflags);
|
tcgetattr(fileno(stdin), &oflags);
|
||||||
@ -502,36 +500,41 @@ static int password_prompt(char *buf, int size)
|
|||||||
/* Ask user if they would like to encrypt the data file on first usage */
|
/* Ask user if they would like to encrypt the data file on first usage */
|
||||||
static void first_time_running(void)
|
static void first_time_running(void)
|
||||||
{
|
{
|
||||||
char ch[3] = {0};
|
char ch[5] = {0};
|
||||||
|
|
||||||
do {
|
do {
|
||||||
system("clear");
|
system("clear");
|
||||||
printf("Encrypt data file? Y/n \n");
|
printf("Creating new data file. Would you like to encrypt it? Y/n (q to quit)\n");
|
||||||
|
|
||||||
if (!strcmp(ch, "y\n") || !strcmp(ch, "n\n"))
|
if (!strcasecmp(ch, "y\n") || !strcasecmp(ch, "n\n")
|
||||||
|
|| !strcasecmp(ch, "yes\n") || !strcasecmp(ch, "no\n")
|
||||||
|
|| !strcasecmp(ch, "q\n"))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} while (fgets(ch, sizeof(ch), stdin));
|
} while (fgets(ch, sizeof(ch), stdin));
|
||||||
|
|
||||||
const char *msg = NULL;
|
if (ch[0] == 'q' || ch[0] == 'Q')
|
||||||
int len = 0;
|
exit(0);
|
||||||
|
|
||||||
if (ch[0] == 'y') {
|
if (ch[0] == 'y' || ch[0] == 'Y') {
|
||||||
do {
|
int len = 0;
|
||||||
printf("Enter a new password (must be at least %d characters)\n", MIN_PASSWORD_LEN);
|
printf("Enter a new password (must be at least %d characters)\n", MIN_PASSWORD_LEN);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
len = password_prompt(user_password.pass, sizeof(user_password.pass));
|
len = password_prompt(user_password.pass, sizeof(user_password.pass));
|
||||||
user_password.len = len;
|
user_password.len = len;
|
||||||
} while (len < MIN_PASSWORD_LEN || len > MAX_PASSWORD_LEN);
|
|
||||||
|
if (len >= MIN_PASSWORD_LEN && len <= MAX_PASSWORD_LEN)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
printf("Password must be between %d and %d characters long.\n", MIN_PASSWORD_LEN, MAX_PASSWORD_LEN);
|
||||||
|
}
|
||||||
|
|
||||||
user_password.data_is_encrypted = true;
|
user_password.data_is_encrypted = true;
|
||||||
msg = "Data file has been encrypted";
|
queue_init_message("Data file has been encrypted");
|
||||||
} else {
|
|
||||||
user_password.data_is_encrypted = false;
|
|
||||||
msg = "Data file has not been encrypted";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
system("clear");
|
system("clear");
|
||||||
queue_init_message(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -610,19 +613,23 @@ static void load_data(Tox *m, char *path)
|
|||||||
|
|
||||||
if (user_password.data_is_encrypted) {
|
if (user_password.data_is_encrypted) {
|
||||||
system("clear");
|
system("clear");
|
||||||
printf("Enter password\n");
|
printf("Enter password (q to quit)\n");
|
||||||
|
|
||||||
do {
|
while (true) {
|
||||||
pwlen = password_prompt(user_password.pass, sizeof(user_password.pass));
|
pwlen = password_prompt(user_password.pass, sizeof(user_password.pass));
|
||||||
user_password.len = pwlen;
|
user_password.len = pwlen;
|
||||||
|
|
||||||
if (-1 != tox_encrypted_load(m, (uint8_t *) buf, len, (uint8_t *) user_password.pass, pwlen)) {
|
if (strcasecmp(user_password.pass, "q") == 0)
|
||||||
|
exit(0);
|
||||||
|
|
||||||
|
if (tox_encrypted_load(m, (uint8_t *) buf, len, (uint8_t *) user_password.pass, pwlen) == 0) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
sleep(2);
|
sleep(2);
|
||||||
|
system("clear");
|
||||||
printf("Invalid password. Try again.\n");
|
printf("Invalid password. Try again.\n");
|
||||||
}
|
}
|
||||||
} while (true);
|
}
|
||||||
|
|
||||||
system("clear");
|
system("clear");
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user