This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
magicka/settings.c

65 lines
1.7 KiB
C
Raw Normal View History

2016-04-10 08:45:02 +00:00
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "bbs.h"
2016-08-06 04:36:36 +00:00
void settings_menu(struct user_record *user) {
2016-04-10 08:45:02 +00:00
char buffer[256];
int dosettings = 0;
char c;
char *hash;
2016-04-10 08:45:02 +00:00
while (!dosettings) {
2016-08-06 04:36:36 +00:00
s_printf("\e[2J\e[1;32mYour Settings\r\n");
s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
s_printf("\e[0;36mP. \e[1;37mPassword (\e[1;33mNot Shown\e[1;37m)\r\n");
s_printf("\e[0;36mL. \e[1;37mLocation (\e[1;33m%s\e[1;37m)\r\n", user->location);
s_printf("\e[0;36mQ. \e[1;37mQuit to Main Menu\r\n");
s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
2016-08-06 04:36:36 +00:00
c = s_getc();
2016-04-10 08:45:02 +00:00
switch(tolower(c)) {
case 'p':
{
2016-08-06 04:36:36 +00:00
s_printf("\r\nEnter your current password: ");
s_readpass(buffer, 16);
hash = hash_sha256(buffer, user->salt);
if (strcmp(hash, user->password) == 0) {
2016-08-06 04:36:36 +00:00
s_printf("\r\nEnter your new password (8 chars min): ");
s_readstring(buffer, 16);
2016-04-10 08:45:02 +00:00
if (strlen(buffer) >= 8) {
free(user->password);
free(user->salt);
gen_salt(&user->salt);
user->password = hash_sha256(buffer, user->salt);
2016-04-10 08:45:02 +00:00
save_user(user);
2016-08-06 04:36:36 +00:00
s_printf("\r\nPassword Changed!\r\n");
2016-04-10 08:45:02 +00:00
} else {
2016-08-06 04:36:36 +00:00
s_printf("\r\nPassword too short!\r\n");
2016-04-10 08:45:02 +00:00
}
} else {
2016-08-06 04:36:36 +00:00
s_printf("\r\nPassword Incorrect!\r\n");
2016-04-10 08:45:02 +00:00
}
}
break;
case 'l':
{
2016-08-06 04:36:36 +00:00
s_printf("\r\nEnter your new location: ");
s_readstring(buffer, 32);
2016-04-10 08:45:02 +00:00
free(user->location);
user->location = (char *)malloc(strlen(buffer) + 1);
strcpy(user->location, buffer);
save_user(user);
}
break;
case 'q':
dosettings = 1;
break;
}
}
}