7
Albright
Re: Allow Spaces in Username Hack (easy!)
  • 2004/5/4 9:58

  • Albright

  • Just popping in

  • Posts: 7

  • Since: 2004/4/25


Shucks. It's just a li'l ol' three-minute hack, and I had to look up more info on regular expressions in order to do it (my regex experience is laughable).

Though one has to wonder that, if it really is this easy and it doesn't seem to break XOOPS at all, just what the XOOPS team's reason for going out of their way to prevent spaces in usernames was in the first place... I'm sure they had one.

6
drksoul
Re: Allow Spaces in Username Hack (easy!)
  • 2004/4/29 9:19

  • drksoul

  • Just popping in

  • Posts: 18

  • Since: 2004/3/24


Spectacular. Simply stellar work, you are a god among XOOPS users!

5
Brad
Re: Allow Spaces in Username Hack (easy!)
  • 2004/4/27 13:57

  • Brad

  • Not too shy to talk

  • Posts: 150

  • Since: 2003/12/4


It'd be nice to see this hack integrated into the core. If you haven't yet, perhaps you should submit it to Feature Requests. If you are not able, or would rather not do it yourself, I can submit it for you.

4
Albright
Re: Allow Spaces in Username Hack (easy!)
  • 2004/4/27 8:22

  • Albright

  • Just popping in

  • Posts: 7

  • Since: 2004/4/25


Ah, yeah, good eye, KubaZ... I also adjusted my post and added a line of code so that people can't spoof as people with spaces in the middle of their names ("The [space] Admin" and "The [space] [space] Admin.") trim() should put the kaibosh on all-space usernames too, so I took that part out as well.

3
KubaZ
Re: Allow Spaces in Username Hack (easy!)
  • 2004/4/27 7:49

  • KubaZ

  • Just popping in

  • Posts: 37

  • Since: 2002/10/9


to avoid fake usernames like 'admin ' (some spaces on the right/left side) we can use php function trim (Strip whitespace from the beginning and end of a string)

..heh..now I've seen that register.php uses trim($uname)
so even we use this hack white spaces before and after username will be deleted



2
wtravel
Re: Allow Spaces in Username Hack (easy!)

Albright,

Wonderfull hack!! I will try and see if that does the trick.

Regards,

Martijn

1
Albright
Allow Spaces in Username Hack (easy!)
  • 2004/4/27 4:42

  • Albright

  • Just popping in

  • Posts: 7

  • Since: 2004/4/25


Normal hack caveats apply.

We're going to edit one file: register.php. Open it up, and go to lines 60-73. It should look something like this...

switch ( $xoopsConfigUser['uname_test_level'] ) {
    case 
0:
        
// strict
        
$restriction '/[^a-zA-Z0-9_-]/';
        break;
    case 
1:
        
// medium
        
$restriction '/[^a-zA-Z0-9_-<>,.$%#@!\'"]/';
        break;
    case 2:
        // loose
        
$restriction = '/[00-40]/';
        break;
    }


The following line of code should be added BEFORE this block of code. This line will prevent people from creating new accounts which "spoof" currently-existing accounts by adding extraneous spaces. For example, without this line, someone could spoof "The [space] Administrator" by creating an account with the name "The [space] [space] Administrator." This person wouldn't really have admin powers, but they could appear to post as the admin.

$uname preg_replace('/s+/'' '$uname);


Now, before the ] in the first two lines that start with $restriction, we want to add "\s", which signifies a whitespace as created by the space bar; on the third $restriction line, it needs to be "\s\". (Depending on your "strictness" setting in the User Info section of the site Preferences, you actually only have to edit the relevant line, but in order to not "break" things should you change this setting in the future, we'll do all three.) Note that \ is a BACKSLASH (the key above Return and below Delete on a Mac or above Enter and below Backspace on a PC), not a / SLASH (which shares a key with the ? question mark.) The block of code, with the line added to the beginning, should look like this...

$uname preg_replace('/s+/'' '$uname);
     switch ( 
$xoopsConfigUser['uname_test_level'] ) {
    case 
0:
        
// strict
        
$restriction '/[^a-zA-Z0-9_-s]/';
        break;
    case 
1:
        
// medium
        
$restriction '/[^a-zA-Z0-9_-<>,.$%#@!\'"s]/';
        break;
    case 2:
        // loose
        
$restriction = '/[00-40s]/';
        break;
    }


Now there's one more thing we gotta do. Let's look at lines 90-92 (they were lines 89-91 before we added that line of code above);

if ( strrpos($uname,' ') > ) {
        
$stop .= _US_NICKNAMENOSPACES."<br />";
    }


We don't want these lines. You could delete them if you want, but I suggest we "comment out" the lines instead. This means we're going to signify this code as a "comment" which should be ignored. To do this, we want to put /* before the block, and */ after it. (Note we're using a / slash this time, and not a \ backslash.)

/*    if ( strrpos($uname,' ') > 0 ) {
        $stop .= _US_NICKNAMENOSPACES."<br />";
    }*/


Save the file, and make a test account with a space in the username to make sure it works.

Xoops seems to work just fine with usernames with spaces... Let me know if something broke in your case.

Login

Who's Online

103 user(s) are online (59 user(s) are browsing Support Forums)


Members: 0


Guests: 103


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits