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