]> skyeroc.xyz Git - dgamelaunch/commitdiff
Stricter check on entered email addresses; the same check is now used for new
authorJilles Tjoelker <jilles@stack.nl>
Sat, 6 Mar 2004 20:34:27 +0000 (20:34 +0000)
committerJilles Tjoelker <jilles@stack.nl>
Sat, 6 Mar 2004 20:34:27 +0000 (20:34 +0000)
accounts as well as changes in existing accounts.

git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@268 db0b04b0-f4d1-0310-9a6d-de3e77497b0e

Changelog
dgamelaunch.c

index 3f12a1af65d16bbe545b51bb64cc8d5d5cd3eb73..d7312d41f19150f907d28145a5c9d2e8e2eafe87 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -8,6 +8,8 @@
        * 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
          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)
        * Make ttyplay use the 'strip' value it remembered from last view.
index bb104ce01733ef1399959dfb65974ec58ca601a6..19cbed77fcc630ea3c33fd5f1ccc748d2af7d91f 100644 (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
 change_email ()
 {
@@ -442,8 +483,7 @@ change_email ()
       mvaddstr (8, 1, "That's the same one as before. Try again?");
       move(1,1);
     }
-    /* rudimentary check for validity */
-    else if (strchr(buf, '@') < strrchr(buf, '.'))
+    else if (check_email (buf))
     {
       mvprintw (8, 1, "Changing email address to '%s'. Confirm (y/n): ", buf);
       if (getch() == 'y')
@@ -861,32 +901,45 @@ newuser ()
 
   /* email step */
 
-  clear ();
-
-  drawbanner (1, 1);
+  error = 2;
+  while (error != 0)
+    {
+      clear ();
 
-  mvaddstr (5, 1, "Please enter your email address.");
-  mvaddstr (6, 1,
-            "This is sent _nowhere_ but will be used if you ask the sysadmin for lost");
-  mvaddstr (7, 1,
-            "password help. Please use a correct one. It only benefits you.");
-  mvaddstr (8, 1, "80 character max. No ':' characters. Blank line aborts.");
-  mvaddstr (10, 1, "=> ");
+      drawbanner (1, 1);
 
-  refresh ();
-  mygetnstr (buf, 80, 1);
+      mvaddstr (5, 1, "Please enter your email address.");
+      mvaddstr (6, 1, "This is sent _nowhere_ but will be used if you ask"
+        " the sysadmin for lost");
+      mvaddstr (7, 1, "password help. Please use a correct one. It only"
+        " benefits you.");
+      mvaddstr (8, 1, "80 character max. No ':' characters. Blank line"
+        " aborts.");
+      mvaddstr (10, 1, "=> ");
 
-  if (strchr (buf, ':') != NULL)
-    graceful_exit (113);
+      if (error == 1)
+        {
+          mvaddstr (12, 1, "There was a problem with your last entry.");
+          move (10, 4);
+        }
 
-  if (buf && *buf == '\0')
-  {
-    free (me->username);
-    free (me->password);
-    free (me);
-    me = NULL;
-    return;
-  }
+      refresh ();
+      mygetnstr (buf, 80, 1);
+      if (check_email (buf))
+        error = 0;
+      else
+        error = 1;
+      if (buf && *buf == '\0')
+      {
+        free (me->username);
+        free (me->password);
+        free (me);
+        me = NULL;
+        return;
+      }
+    }
 
   me->email = strdup (buf);
   me->env = calloc (1, 1);