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

One more thing...

Do you have friends or a Facebook group who you think would find this useful? Share this with them and then let me know what they think.

Want to supercharge your website?

  Our website loads FAST ... just 1.29 seconds. We're hosted on FAST InMotion servers We want YOUR website to be fast too, so we've gotten you an exclusive deal - 47% OFF for DART Creations friends + FREE domain! Check it out NOW!

Translate

who are we?

DART Creations is run by David Attard - working in and around the web design niche for more than 12 years, we provide actionable tips for people who work with and on websites. We also run DronesBuy.net - a website for drone hobbyists

David attard

Follow us on Social

         

 

 

 

Popular Content

Joomla extensions to take your website to the NEXT level

Is your Joomla website reaching its full potential? We install many of these extensions on almost ALL of our Joomla sites - why don't you check them out our list of Joomla Extensions and see whether you can take your site to the next level?

Where are we hosted?

This site is proudly powered by FAST VPS InMotion Servers and given an insane speed thanks to MaxCDN!

Web Hosting MaxCDN - Speed up your website

 

InMotion Hosting Review - Recommended Web Hosting servers for business, Joomla, WordPress and ecommerce websites.

InMotion Hosting Review

Advertise on DART-Creations.com

DART Creations is interested in developing partnerships with mutual benefit. If you like the stuff we publish and would like to develop a relationship, we'd be happy to hear from you. Go on - drop us a line - we'd love to hear from you :-)

The Outstanding october Bundle

30 premiums fonts, 11 graphic packs for$29. Get it NOW - October Only!

Outstanding October bundle

New! DIVI 3.0 WordPress TeMPLATE + PageBuilder - 10% OFF Limited Launch offer

You'll surely create a perfect website with Divi 3.0!

Divi 3