Enable Special Characters in Username

For Joomla! 2.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Note: All 1.6, 1.7 and 3.5 releases have reached end of life and should be updated to 3.x.

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
thunderclap
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Wed Jan 18, 2012 7:20 pm

Enable Special Characters in Username

Post by thunderclap » Wed Jun 20, 2012 5:37 pm

My main site is run on vBulletin, but I'm adding a reviews section using jReviews (and Joomla, obviously). In doing so I use jFusion to bridge vBulletin a Joomla users. The problem is some of the 13,000+ registered users have special characters in their username such as an apostrophe, something Joomla doesn't like.

I found some code that could be changed to allow for special characters but this is for Joomla 1.5. I can't find the files to alter in 2.5. So... is there a way?

studiok
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Thu Mar 31, 2011 1:24 pm

Re: Enable Special Characters in Username

Post by studiok » Tue Aug 07, 2012 10:19 am

Hi Thunderclap,

Did you ever find a way to allow special characters in Username in Joomla2.5.
I also have a database to import with usernames which have special characters ('&' in my case).

thunderclap
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Wed Jan 18, 2012 7:20 pm

Re: Enable Special Characters in Username

Post by thunderclap » Tue Aug 07, 2012 9:54 pm

studiok wrote:Hi Thunderclap,

Did you ever find a way to allow special characters in Username in Joomla2.5.
I also have a database to import with usernames which have special characters ('&' in my case).
Nope. Still stuck on this one.

studiok
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Thu Mar 31, 2011 1:24 pm

Re: Enable Special Characters in Username

Post by studiok » Wed Sep 19, 2012 8:56 am

I kept looking into this, as it continued to be an issue for me. I was using Community Builder 1.7.1 and CBjuice2 to import users from an old Joomla 1.0 site.

Because I was using Community Builder there seems to be a double validation of Username, the native Joomla2.5 one and a Community builder one.

The Joomla validation is controlled by 3 files:

libraries/joomla/database/table/user.php - line 197
media/system/js/validate.js - line 5
media/system/js/validate-uncompressed.js - line 33

In user.php you should see on line 197 this following code:

Code: Select all

if (preg_match("#[<>\"'%;()&]#i", $this->username) || strlen(utf8_decode($this->username)) < 2)
		{
			$this->setError(JText::sprintf('JLIB_DATABASE_ERROR_VALID_AZ09', 2));
			return false;
		}
In my case I just wanted to allow '&' be used so removed it from the first line. For my following example I am just removing & but you should be able to remove whichever character you want to allow.

The compressed javascript is the one I believe Joomla uses, the uncompressed is for development, but I changed both none the less.
In validate.js you will see on the 5th line:

Code: Select all

this.setHandler("username",function(a){regex=/[<|>|"|'|%|;|(|)|&]/i;return!regex.test(a)})
From here I removed the '|&' from the end of the regex condition.

In validate-uncompressed.js on line 33 (code shows 31-36):

Code: Select all

this.setHandler('username',
			function (value) {
				regex = new RegExp("[\<|\>|\"|\'|\%|\;|\(|\)|\&]", "i");
				return !regex.test(value);
			}
		);
I removed '|\&'
Changing those 3 files allows you to create a Username with an '&' in it, through the normal joomla User manager.


However I was using Community Builder and could still not use the &. With a lot of searching I found an old post using Joomla 1.0 and CB (http://forum.joomla.org/viewtopic.php?t=26472) which helped point me in the right direction.

If using Community Builder there are 2 files you must change.

1. components\com_comprofiler\comprofiler.html.php - lines 217, 225, 1224, 1232
You will see the RegExp like

Code: Select all

var r = new RegExp("[\<|\>|\"|\'|\%|\;|\(|\)|\&]", "i");
and should remove the |\& from it in all four lines.

2. administrator\components\com_comprofiler\view\view.user.php - line 100, 108
Again you will see the RegExp like

Code: Select all

var r = new RegExp("^[\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-]*$", "i");
and should remove the |\& from both lines.

Note that this just allowed me upload users with CBjuice2 and allowed '&' in username, however if you try to change anything in the community builder interface it will still not allow special characters in the username.

There must be a javascript file checking the Username, I am yet to find it, possibly something to do with 'components\com_comprofiler\js\jquery-1.5.2\jquery.validate.js' as this file is called when editing a user in CB.

Hope this helps anyone with this problem.

User avatar
humvee
Joomla! Master
Joomla! Master
Posts: 14704
Joined: Wed Aug 17, 2005 10:27 pm
Location: Kent, England

Re: Enable Special Characters in Username

Post by humvee » Thu Sep 20, 2012 3:58 pm

[Mod note: Moved from Admin Forum to 2.5 Code Forum as this is specifically about trying to locate specific functionality of the core code;]
As a sideline be aware that any amendments to the core code may be subsequently overwritten during a future update thereby returning the site to its original restrictions and you might also look to introduce these changes by creating custom Extensions (if none already exist).

francota
Joomla! Intern
Joomla! Intern
Posts: 90
Joined: Sun Dec 30, 2012 4:25 pm

Re: Enable Special Characters in Username

Post by francota » Wed Nov 26, 2014 8:16 am

Hello studiok
I need users are able to use & in their username.
First of all I modified the rule of joomla core to accept the character &.
Than I followed your suggestion to modify the file of CB, but sill I have the problem when I register user with &, infact CB answer me:"Please enter a valid Username:. No spaces, more than 2 characters and contain 0-9,a-z,A-Z"

I think the problem now is in the "components\com_comprofiler\js\jquery-1.5.2\jquery.validate.js" How you sayd ;)
Did you find what to change in jquery.validate.js???
I opened that file but I didnt understand what change :(

I hope in your help :-[
Thanks
Frank


Locked

Return to “Joomla! 2.5 Coding”