Jump to content

Registration Disallowed Names


Baving

Recommended Posts

Hello,

On my registration script it checks for some disallowed usernames in a database which are not allowed to be registered, for example moderator.

What code could I use in php / mysql query to check if someone is trying to register disallowed names?

Also it needs to be able to use a sort of wildcard. So if I tried to register moderator-05 it wouldn't allow it. With moderator being the banned word.

Thanks
Link to comment
Share on other sites

use where $needle is your inputted usernames and $haystack is a string of your disallowed usernames. you could either hardcode these prohibitted usernames in $haystack, or better yet, store them in your db and query for them and store them in $haystack before you call the function.

[code]
function is_substr($needle, $haystack){
      $pos = strpos($haystack, $needle);

      if ($pos === false) {
              // inputted username was not found as a disallowed value.
              return false;
      } else {
              // inputted username is not allowed.
              return true;
      }
}[/code]
Link to comment
Share on other sites

I have this function: -

[code]function name_filter($name) {

  $name = mysql_escape_string(strip_tags($name));
  $query = mysql_query("SELECT `word` FROM filter WHERE type = 'N'");

$word = mysql_fetch_array($query);

foreach ($word as $check) {
 

  if(preg_match("/$check/", $name)) return TRUE;

}} [/code]

But using preg_match is there any way to include like a * character to use as a wild card.

So say *php would block Greatphp but not Greathp
Link to comment
Share on other sites

do not use preg_match() if you only want to check if one string is contained in another string. Use strpos() or strstr() instead as they will be faster. i think i might have what you're looking for.

try:
[code]
function name_filter($name) {

  $name = mysql_escape_string(strip_tags($name));
  $query = mysql_query("SELECT `word` FROM filter WHERE type = 'N'");
  $word = mysql_fetch_array($query);

  foreach ($word as $check) {
      // swap out the preg_match() function with:
      $pos = strpos($check, $name);

      if ($pos === false) {
              // the $check value was not found in $name, continue.
      } else {
              // the $check value was found in $name, disallow username.
      }

  } // end foreach
} // end function
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.