Update to only allow alpha characters in usernames

This commit is contained in:
Andrew Pamment 2016-03-28 17:26:42 +10:00
parent a5103db5dc
commit 1ebd79c880

13
users.c
View File

@ -348,6 +348,7 @@ struct user_record *new_user(int socket) {
char c; char c;
int nameok = 0; int nameok = 0;
int passok = 0; int passok = 0;
int i;
user = (struct user_record *)malloc(sizeof(struct user_record)); user = (struct user_record *)malloc(sizeof(struct user_record));
s_putstring(socket, "\r\n\r\n"); s_putstring(socket, "\r\n\r\n");
@ -365,11 +366,17 @@ struct user_record *new_user(int socket) {
continue; continue;
} }
if (strchr(buffer, '%') != NULL) { for (i=0;i<strlen(buffer);i++) {
s_putstring(socket, "Sorry, invalid character.\r\n"); if (!(tolower(buffer[i]) >= 97 && tolower(buffer[i]) <= 122)) {
s_putstring(socket, "Sorry, invalid character, can only use alpha characters.\r\n");
nameok = 1;
break;
}
}
if (nameok == 1) {
nameok = 0;
continue; continue;
} }
if (strcasecmp(buffer, "unknown") == 0) { if (strcasecmp(buffer, "unknown") == 0) {
s_putstring(socket, "Sorry, that name is reserved.\r\n"); s_putstring(socket, "Sorry, that name is reserved.\r\n");
continue; continue;