aboutsummaryrefslogtreecommitdiff
path: root/ctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'ctl.c')
-rw-r--r--ctl.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/ctl.c b/ctl.c
index 2bda5a7..58db942 100644
--- a/ctl.c
+++ b/ctl.c
@@ -5,6 +5,8 @@
#include <time.h>
#include "cforum.h"
+#define MAXMSG 256
+
/* Print UNIX timestamp as written date. */
void
printdate(int timestamp)
@@ -51,8 +53,8 @@ newpost()
void
newuser()
{
-#define MAXMSG 256
- char *captcha, *confirm, *hlite, msg[MAXMSG], *name, *full, *p, *pass, *v;
+ char *captcha, *confirm, *name, *full, *pass;
+ char *hlite, msg[MAXMSG], *p, *v;
char title[] = "New User";
int i;
struct user *user;
@@ -123,12 +125,12 @@ newuser()
goto err;
}
-#define ISVIS(c) ((unsigned int)c >= 20)
+#define ISVIS(c) ((unsigned char)c >= 32)
#define ISALNUM(c) (c>='A' && c<='Z' || c>='a' && c<='z' || c>='0' && c<='9')
/* Constrain character sets. */
for(i = 0; name[i]; i++)
- if(!ISVIS(name[i]) || !(name[i] == '_' || ISALNUM(name[i]))){
+ if(!name[i] == '_' && !ISALNUM(name[i])){
hlite = strdup("name");
snprintf(msg, MAXMSG,
"Username may only contain ASCII letters, "
@@ -174,8 +176,11 @@ newuser()
user->hash = pass; /* TODO */
if(!adduser(user)){
- snprintf(msg, MAXMSG, "Could not add user to database: %s",
- sqlite3_errmsg(db));
+ if(strcmp(sqlite3_errmsg(db), "column name is not unique")==0)
+ snprintf(msg, MAXMSG, "Username already exists.");
+ else
+ snprintf(msg, MAXMSG, "Could not create user: %s. ",
+ sqlite3_errmsg(db));
goto err;
}