Stricter check on entered email addresses; the same check is now used for new

accounts as well as changes in existing accounts.


git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@268 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
This commit is contained in:
Jilles Tjoelker 2004-03-06 20:34:27 +00:00
parent 9beae9e40d
commit d71b47be7e
2 changed files with 79 additions and 24 deletions

View File

@ -8,6 +8,8 @@
* Selecting a game to watch with an uppercase letter attempts to * Selecting a game to watch with an uppercase letter attempts to
change the window size to the game's via the \033[8;<r>;<c>t change the window size to the game's via the \033[8;<r>;<c>t
sequence. sequence.
* Stricter check on entered email addresses; the same check is now
used for new accounts as well as changes in existing accounts.
1.4.3 (2004/02/28) 1.4.3 (2004/02/28)
* Make ttyplay use the 'strip' value it remembered from last view. * Make ttyplay use the 'strip' value it remembered from last view.

View File

@ -417,6 +417,47 @@ inprogressmenu ()
/* ************************************************************* */ /* ************************************************************* */
/*
* Check email address, returns 1 if valid, 0 otherwise.
* Doesn't recognize addresses with parts in double-quotes.
* Addresses with a colon in them are always rejected.
*/
int
check_email (char *s)
{
char *atomchars = "!#$%&'*+-/=?^_`{|}~" "0123456789"
"abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int f;
if (*s == '@')
return 0;
while (*s != '\0' && *s != '@')
{
if (strchr(atomchars, *s) == NULL)
return 0;
s++;
if (*s == '.')
s++;
}
if (*s == '\0')
return 0;
s++;
f = 0;
while (*s != '\0')
{
if (strchr(atomchars, *s) == NULL)
return 0;
s++;
if (*s == '.')
s++, f = 1;
}
return f;
}
void void
change_email () change_email ()
{ {
@ -442,8 +483,7 @@ change_email ()
mvaddstr (8, 1, "That's the same one as before. Try again?"); mvaddstr (8, 1, "That's the same one as before. Try again?");
move(1,1); move(1,1);
} }
/* rudimentary check for validity */ else if (check_email (buf))
else if (strchr(buf, '@') < strrchr(buf, '.'))
{ {
mvprintw (8, 1, "Changing email address to '%s'. Confirm (y/n): ", buf); mvprintw (8, 1, "Changing email address to '%s'. Confirm (y/n): ", buf);
if (getch() == 'y') if (getch() == 'y')
@ -861,32 +901,45 @@ newuser ()
/* email step */ /* email step */
clear (); error = 2;
while (error != 0)
{
clear ();
drawbanner (1, 1); drawbanner (1, 1);
mvaddstr (5, 1, "Please enter your email address."); mvaddstr (5, 1, "Please enter your email address.");
mvaddstr (6, 1, mvaddstr (6, 1, "This is sent _nowhere_ but will be used if you ask"
"This is sent _nowhere_ but will be used if you ask the sysadmin for lost"); " the sysadmin for lost");
mvaddstr (7, 1, mvaddstr (7, 1, "password help. Please use a correct one. It only"
"password help. Please use a correct one. It only benefits you."); " benefits you.");
mvaddstr (8, 1, "80 character max. No ':' characters. Blank line aborts."); mvaddstr (8, 1, "80 character max. No ':' characters. Blank line"
mvaddstr (10, 1, "=> "); " aborts.");
mvaddstr (10, 1, "=> ");
refresh (); if (error == 1)
mygetnstr (buf, 80, 1); {
mvaddstr (12, 1, "There was a problem with your last entry.");
move (10, 4);
}
if (strchr (buf, ':') != NULL) refresh ();
graceful_exit (113); mygetnstr (buf, 80, 1);
if (buf && *buf == '\0') if (check_email (buf))
{ error = 0;
free (me->username); else
free (me->password); error = 1;
free (me);
me = NULL; if (buf && *buf == '\0')
return; {
} free (me->username);
free (me->password);
free (me);
me = NULL;
return;
}
}
me->email = strdup (buf); me->email = strdup (buf);
me->env = calloc (1, 1); me->env = calloc (1, 1);