The long awaited Kraknet registration system is
finally online in its rudimentary state. In a fury of studying for a
programming competition, I took the time to figure out regular expressions in
C, which made it very easy to make a fairly safe registration system. It's not
immediately obvious, but in order to use normal regex symbols like ^ and
$ (beginning and end of string anchors, respectively) you must escape
them.
For example's sake, consider the regex used to check that newly registered
names are all lowercase letters, at least four of them and no more than 31. I
actually used ` (backtick) and ' (apostrophe) instead of ^ and $;
it works the same way.
regex_t loweral;
regcomp(&loweral,"\\`[a-z]\\{4,31\\}\\'",REG_NOSUB);
Setting up the regex in this way allows you to match the entire string with
no substring elements. This is perfect for quickly evaluating, as I was in this
case, usernames. When it comes time to actually match, it's fairly
straightforward again.
if(regexec(&loweral,user,0,NULL,0)){
printf("Username must be 4 to 31 characters, ...\r\n");
return -1;
}
regexec will return some non-zero value if the string doesn't match
the regular expression, and therefore isn't a value user name. A similar system
was used to validate passwords, and you can see the whole hacked together
registration code here.
You might also have noticed the slight changes to the style of Kraknet. The
very plain old CSS has been replaced by somewhat less plain new CSS. I was just
sick of looking at high-contrast, bold colors everywhere.