Change characters allowed in JOOMLA usernames

Discussion in 'PHP/MySql' started by balajia, Jul 19, 2010.

  1. balajia New Member

    Member Since:
    Jul 1, 2010
    Message Count:
    27
    Likes Received:
    1
    Occupation:
    Web Developer
    Location:
    India
    By default, Joomla does not allow certain characters to be used in usernames (e.g. hypens, brackets, square brackets etc.). This is done for good reasons, especially security. However, sometimes for different reasons, you will need to allow certain usernames. To change the characters allowed by Joomla you need to change the core code as described below.
    We are simply removing the hyphen \- from the regular expression which searches for invalid characters.


    File: includes/joomla.php

    From:

    if (eregi( "[\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-]", $this->username) || strlen( $this->username ) < 3) {
    $this->_error = sprintf( addslashes( _VALID_AZ09 ), addslashes( _PROMPT_UNAME ), 2 );
    return false;
    }

    To:
    if (eregi( "[\<|\>|\"|\'|\%|\;|\(|\)|\&|\+]", $this->username) || strlen( $this->username ) < 3) {
    $this->_error = sprintf( addslashes( _VALID_AZ09 ), addslashes( _PROMPT_UNAME ), 2 );
    return false;
    }


    File: components/com_user/user.html.php

    From:
    var r = new RegExp("[\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-]", "i");

    To
    var r = new RegExp("[\<|\>|\"|\'|\%|\;|\(|\)|\&|\+]", "i");


    File: administrator/components/com_user/admin.users.html.php

    From:
    var r = new RegExp("[\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-]", "i");

    To:
    var r = new RegExp("[\<|\>|\"|\'|\%|\;|\(|\)|\&|\+]", "i");

    That's it. You should now be able to register a new user with a hyphen.

Share This Page