Jump to content
MakeWebGames

Help Securing Register


M0B2

Recommended Posts

I've been trying to secure the register page on the lite version of MCCodes. The bit im interested in is making sure that when people register a new user they can only have numbers or letters in the username, but I to be honest I just dont know how to do it. The lite versions allows I think all characters including special ones (e.g. * , ; @).

Any help would be appreciated thanks.

Link to comment
Share on other sites

you can use simple regular expressions like:

[^a-zA-Z0-9]

That would match any NON allowed character and therefore trigger your filter or

[^\d\w]

 

For the PHP code:

$username="toto";
$badUsername="bad!one";

$pattern="/[^a-zA-Z0-9] /";

if(preg_match($pattern,$username) != 0) // not a good one!
   echo "$username is not an accepted username<br />";
else
   echo "welcome in the game $username<br />";

if(preg_match($pattern,$badUsername) != 0) // not a good one!
   echo "$badUsername is not an accepted username<br />";
else
   echo "welcome in the game $badUsername<br />";
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...