Jump to content

Archived

This topic is now archived and is closed to further replies.

Baving

Registration Disallowed Names

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

Share this post


Link to post
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]

Share this post


Link to post
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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.