CMS MADE SIMPLE FORGE

Frontend Users

 

[#10107] Cannot add user - Invalid Username caused by preg_match not working

avatar
Created By: (jamaa)
Date Submitted: Fri Jul 11 04:41:33 -0400 2014

Assigned To:
Version: 1.23.5
CMSMS Version: 1.11.10
Severity: Critical
Resolution: Fixed
State: Closed
Summary:
Cannot add user - Invalid Username caused by preg_match not working
Detailed Description:
I cannot add users anymore. The error message displayed is "Invalid Username",
no matter what I try. Not sure since which version this problem exists but it
used to work before.

I was able to pinpoint the problem here: 

function validate_username in class.feu_std_consumer.php:

when I comment out the following lines, the error message no longer appears and
I can add users again:

else if( !preg_match( '/^[a-zA-Z0-9_-\s\.]*$/', $username ) ) {
    return false;
}

Checking the forums, I found this thread:
http://http://forum.cmsmadesimple.org/viewtopic.php?f=7&t=69934&p=311387 where
the problem was resolved by downgrading to php 5.3.28. On our server, the php
version is 5.2.17.

So perhaps there is a problem with the preg_match function in certain php
versions?


History

Comments
avatar
Date: 2014-08-03 09:09
Posted By: Robert Campbell (calguy1000)

just tested, no problems here.
      
avatar
Date: 2014-09-25 04:16
Posted By: Sven (kdvs)

I ran into a similar problem this morning. No matter what type of username I
try, I keep getting the Invalid Username error message. I couldn't find the
class.feu_std_consumer.php to check if commenting the piece of code helps. Any
ideas?
      
avatar
Date: 2014-11-03 05:29
Posted By: stephen cooper (scooper)

Just had this problem as well just on one particular server. It does seem to be
an issue with the preg_match

I was getting a PHP warning 'Compilation failed: invalid range in character
class'

According to a comment on this post on Stack Overflow the check for a hyphen
needs to be escaped or moved to the end of the match:

http://stackoverflow.com/questions/24764212/preg-match-compilation-failed-invalid-range-in-character-class-at-offset-20

I've just escaped the hyphen in our code and it seems to have done the trick. 

So, in feu 124.1  that's changing line 179 from:

else if( !preg_match( '/^[a-zA-Z0-9_-\s\.]*$/', $username ) ) {

to

else if( !preg_match( '/^[a-zA-Z0-9_\-\s\.]*$/', $username ) ) {

I'm no regexepert so I'll leave it to you to check that's doing the right thing.
but it seems to work for me.

s.


      
avatar
Date: 2014-11-04 05:35
Posted By:  (jamaa)

escaping the hyphen as stephen suggested seems to be working for me as well
      
avatar
Date: 2015-01-19 14:23
Posted By:  (jamaa)

seems to be have been fixed in version 1.24.2 by adding the hyphen as suggested
by stephen
      
Updates

Updated: 2015-01-19 14:23
resolution_id: 11 => 7

Updated: 2015-01-15 23:35
state: Open => Closed

Updated: 2014-08-03 09:09
resolution_id: => 11