Deny usernames containing certain words

Results 1 to 8 of 8
  1. #1
    Valued Member HabbixDK is offline
    MemberRank
    Mar 2013 Join Date
    121Posts

    Deny usernames containing certain words

    Hey guys I was just wondering if anyone had made something so usernames containing a word like "fuck" would be denied to register?


  2. #2
    Valued Member BronzeSpider547 is offline
    MemberRank
    Dec 2015 Join Date
    139Posts

    Re: Deny usernames containing certain words

    Add this to your register in php.
    PHP Code:
    if(strpos($_POST["username"], 'fuck') !== false
    {
        echo 
    '<script>alert("You may not use that username!");</script>';


  3. #3
    Valued Member HabbixDK is offline
    MemberRank
    Mar 2013 Join Date
    121Posts

    Re: Deny usernames containing certain words

    I'm using RevCMS tho :P

  4. #4
    Hakuna Matata Matata is offline
    MemberRank
    Sep 2012 Join Date
    DenmarkLocation
    807Posts

    Re: Deny usernames containing certain words

    Quote Originally Posted by HabbixDK View Post
    I'm using RevCMS tho :P
    Doesn't change anything.

  5. #5
    :joy: Jonteh is offline
    MemberRank
    Apr 2007 Join Date
    New York, USALocation
    3,375Posts

    Re: Deny usernames containing certain words

    Better option:

    Code:
    $entered_name = strtolower($_POST["username"]);
    $bannedNameParts = array('fuck', 'cunt', 'shit', 'anal', 'ragezoneisgood');
    if(in_array($entered_name, $bannedNameParts)) { die('Username part is banned! Shit bro!'); }

  6. #6
    Valued Member HabbixDK is offline
    MemberRank
    Mar 2013 Join Date
    121Posts

    Re: Deny usernames containing certain words

    I tried this however when I add more than 2 swearwords my site won't load. Anyone got a suggestion?
    final public function validName($username) {
    if(strlen($username) <= 25 && ctype_alnum($username))
    {
    if (strpos($username, "fuck") === FALSE) {
    if (strpos($username, "cunt") === FALSE) {


    return true;
    }
    }
    else
    {
    return false;
    }
    }

  7. #7
    Member Haidyn is offline
    MemberRank
    Jun 2007 Join Date
    ChicagoLocation
    96Posts

    Re: Deny usernames containing certain words

    Quote Originally Posted by HabbixDK View Post
    I tried this however when I add more than 2 swearwords my site won't load. Anyone got a suggestion?
    You're missing a bracket and checking each word like that is poor, if you turn on PHP error displaying it'll show you the error and not just go white.
    Jonteh's suggestion of an array is easily expandable, try:

    Code:
    function checkName($username) {
    
        if(strlen($username) <= 25 && ctype_alnum($username)) { 
    
            $bannedNames = array('fuck', 'cunt');
            if (in_array($username, $bannedNames)) {    
    
            return true;
    
            } else {
    
            return false;
    
            }
        }
    }

  8. #8
    Account Upgraded | Title Enabled! Alozi is offline
    MemberRank
    Nov 2014 Join Date
    SwedenLocation
    452Posts

    Re: Deny usernames containing certain words

    Quote Originally Posted by HabbixDK View Post
    I'm using RevCMS tho :P
    RevCMS has nothing to do with the php language.

    UberCMS are php too.

    All big cms'es are based on php.



Advertisement