Notice: Trying to get property of non-object in /home/dartcrea/public_html/dartcreations3/plugins/system/sdgoogleauthorship/sdgoogleauthorship.php on line 46

#16 - Change characters allowed in Joomla usernames

#16 - Change characters allowed in Joomla usernames

Version: Joomla 1.0.x

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.

You will need to edit several core files. Always make sure you have a full backup of the original source code before doing any changes. Also remember that any update will cause these changes to disappear, so make sure to keep track of the changes you have done. My personal way of doing this is to create a hacks.txt file, with the exact file changed, the code before and the code after, which is stored both locally and on the webserver, ideally in a hidden folder.

Changes to core code

In the example below we are removing just the hyphen character. We are simply removing the hyphen \- from the regular expression which searches for invalid characters. The \ is an escape character, whilst the pipe is used as a delimeter, so both have to be removed as well.

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 without a hyphen.

PS. Remeber to backup before doing any core code changes.


Translate

10,000+ Users trust us - Subscribe

Follow us on Facebook!

Joomla Facebook Like Popup