vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.0 Full Releases (https://vborg.vbsupport.ru/forumdisplay.php?f=33)
-   -   Restrict usernames to alphanumeric and underscore (https://vborg.vbsupport.ru/showthread.php?t=73559)

Reynaldovb 12-30-2004 10:00 PM

Restrict usernames to alphanumeric and underscore
 
In response to
http://www.vbulletin.com/forum/showt...614#post772614

User memobug wanted (and myself too) to have a way to restrict usernames to alphanumeric chars and underscore. To me it has been a headache with a lot of users because their password didn't work, just to find after investigation that their usernames had an space and they were writing it without it. I hope this helps others as it has helped me.

Here are the instructions to do it.

1) Go to your Admin Control Panel, Phrases Manager and create a new phrase named "username_invalidchars" in the "Front-end error messages" section.

For the text use something like "Username has invalid characters. Only characters allowed are letters, numbers and underscore."



2.- Open /forums/register.php

Somewhere around line 187 you will find the following
PHP Code:

$errors = array(); 

Add the following just below that
PHP Code:

//--------------------------------------------------
    // check username does not contain UNWANTED characters
    
if (preg_match('/[^a-zA-Z0-9\_]+/'$_POST['username']))
    {
        
//eval(print_standard_error('error_username_semicolon'));
        
eval('$errors[11] = "' fetch_phrase('username_invalidchars'PHRASETYPEID_ERROR) . '";');
    }
//------------------------------------------------- 


That's it, enjoy it.

memobug 12-31-2004 10:51 AM

Many thanks for this. I will be checking it out over the next week or so. It will come in very handy with some new features we hope to add to our website. One for example puts the username in a path to create a custom folder, so cleaning up the usernames like this is ideal.

Regards,

Matt

Reynaldovb 12-31-2004 12:19 PM

Memo, I must warn you that this not correct current usernames, just the new ones. If you would like something like that, you would have to run a query directly against the DB searching and Replacing forbidden characters and then rebuilding user count and titles.

pagekeeper 12-31-2004 02:36 PM

just curious what symbols does it block ?

i was told to use the illegal username thing, but at least this will do it properly...

i dont want to block the underscore ..... ? but i do want to block all of the following:

! " £ $ % ^ & * ( ) + - = : ~ # / \ ` ¬ | ? . , > <

memobug 01-01-2005 09:24 AM

Quote:

Originally Posted by Reynaldovb
Memo, I must warn you that this not correct current usernames, just the new ones. If you would like something like that, you would have to run a query directly against the DB searching and Replacing forbidden characters and then rebuilding user count and titles.

Thanks, yes I'll have to find a way put all those existing folks with noncompliant usernames into their own group and get some kind of email notification out to them that their usernames were revised.

Concerning the instructions, installation went fine. You might want to clarify that the new phrase goes in "Front-End Error Messages" not Front-End User Messages" (which doesn't exist).

Thanks again,

Matt

memobug 01-01-2005 09:26 AM

Quote:

Originally Posted by pagekeeper
just curious what symbols does it block ?

i was told to use the illegal username thing, but at least this will do it properly...

i dont want to block the underscore ..... ? but i do want to block all of the following:

! " ? $ % ^ & * ( ) + - = : ~ # / \ ` ? | ? . , > <

As it's written, it accepts alphanumerics (A-Z a-z 0-9) and the underscore character _
No other symbols or spaces.

Regards,

Matt

rlamego 01-06-2005 04:33 AM

Thanks Reynaldo!

memobug 01-06-2005 07:00 AM

80 new members registered in the past five days. Not a one with a wacko username.
The days of

.:VirtualInsanity:.
/<not
" J-i-m "

Are finally over. Thank you!

Regards,

Matt

Odysseus 01-10-2005 12:17 PM

Will this hack allow usernames with a blank space, such as "John Doe", or will this allow only "John_Doe"?

Reynaldovb 01-15-2005 10:28 PM

Quote:

Originally Posted by Odysseus
Will this hack allow usernames with a blank space, such as "John Doe", or will this allow only "John_Doe"?

It will only allow "John_Doe" not "John Doe" or "John-Doe"

shawno 01-17-2005 12:07 PM

Reynaldovb,

Thank you
Thank you
Thank you

To be suprised I am not sure why this isn't a default item within vB. The amount of work generated by users saying "my log in doesn't work" all because of spaces and symbols is incredible.

Shawno

T3MEDIA 01-18-2005 02:23 AM

Do I put \- at then end to add the "-" symbol? I dont mind having that as well.

Reynaldovb 01-18-2005 04:58 AM

T3Media:

Yes, it would be something like this:
PHP Code:

if (preg_match('/[^a-zA-Z0-9\_\-]+/'$_POST['username'])) 


T3MEDIA 01-20-2005 12:29 PM

Respect due. Thanks. Just needed to verify.

Mechanical Mind 01-23-2005 01:30 PM

* clicks install *

I haven't had a problem with user names like >>..@---@..<< yet !!!

However, I don't want to have such problems!!!

Thank you. I'm going to test this out. And I only have 85 members, so I will email a few of them to notify them that an underscore has been added to their names. (I will add them manually)

Mechanical Mind 01-23-2005 03:32 PM

Does anybody which part in CSS to modify the error message color. The error message color on my forum is so light, that it can barely be seen.

Thanks.

UPDATE..........

I found it. Page Background, Font Color

PIKenPIK 02-07-2005 07:28 AM

i've installed V3.0.6

following code in register.php

PHP Code:

    $errors = array();

    
// check username does not contain semi-colons
    
if (preg_match('/(?<!&#[0-9]{3}|&#[0-9]{4}|&#[0-9]{5});/'$_POST['username']))
    {
        
//eval(print_standard_error('error_username_semicolon'));
        
eval('$errors[10] = "' fetch_phrase('username_semicolon'PHRASETYPEID_ERROR) . '";');
    } 

Is that the same or what?

Lizard King 02-07-2005 10:08 AM

PHP Code:

if (preg_match('/[^a-zA-Z0-9\_\ \]+/'$_POST['username'])) 

Is this the correct code if I want to allow space in user names ?
I am using one :)

Reynaldovb 02-07-2005 04:11 PM

Lizard King:
No, I think the correct way to do it would be something like this:
PHP Code:

if (preg_match('/[^a-zA-Z0-9\_\s]+/'$_POST['username'])) 


clearchannel 02-19-2005 01:17 PM

I would like to install this hack in vB 3.06. I would also like to allow spaces in usernames. Which of the above code would be correct to use in 3.06?

Thanks

Tomek 02-19-2005 03:38 PM

Quote:

Originally Posted by clearchannel
I would like to install this hack in vB 3.06. I would also like to allow spaces in usernames. Which of the above code would be correct to use in 3.06?

PHP Code:

 if (preg_match('/[^a-zA-Z0-9\_\s]+/'$_POST['username'])) 

The \s is for spaces.

Andy 02-20-2005 03:14 AM

Thank you Reynaldovb. The hack works perfectly. I also allowed space and the period.

evilTone 02-20-2005 08:55 PM

installed
nice simple hack

mucho thanks

slix 02-24-2005 04:34 PM

This is great but I need it to go one further..... my new users must have both letters and numbers in their user name. How do I do that?

slix 02-27-2005 06:56 AM

*bump*

rjordan 02-28-2005 04:26 PM

It looks to me that it will allow numbers and letters already.

slix 02-28-2005 08:04 PM

Quote:

Originally Posted by rjordan
It looks to me that it will allow numbers and letters already.

Yea I know it will, but I need it to force users to have both numbers and letters in their user name. For example "fred_20".

Any one?

rjordan 03-06-2005 12:35 PM

I have been looking, but have not found anything that I can get working. This WOULD be nice to have...

Alphawolf83 11-28-2005 05:30 PM

Simple little nice hack *clicks install* :)

Tk1 02-01-2006 03:56 AM

Hi all,

Will this work on vB 3.5.3 ?

If not, can anyone... perhaps port or upgrade it ?

Reynaldovb 02-01-2006 04:04 AM

It would probably work but it is not recommended, and my knowledge about how vB 3.5+ works is not as good as I would want to. I could try to port it next weekend as I need it for my forums too. :-(

Reynaldovb 02-01-2006 07:13 AM

Well, what do you know? I decided to give it a try and in just a few minutes I had a working version for vB 3.5.x :-)

https://vborg.vbsupport.ru/showthread.php?t=106877

Roms 02-14-2006 12:51 AM

Thanks, Works great!! Cheers!

josiespencer 09-16-2006 05:04 PM

I couldn't find your original anchor point in register.php so I put it in the code just after referrer and before the image check. It looks like this:

PHP Code:

// check referrer
if ($vbulletin->GPC['referrername'] AND !$vbulletin->userinfo['userid'])
{
$userdata->set('referrerid'$vbulletin->GPC['referrername']);
}

//-------------------------------------------------- 
// check username does not contain UNWANTED characters 
if (preg_match('/[^a-zA-Z0-9\_]+/'$_POST['username'])) 

    
//eval(print_standard_error('error_username_semicolon')); 
    
eval('$errors[11] = "' fetch_phrase('username_invalidchars'PHRASETYPEID_ERROR) . '";'); 

//-------------------------------------------------  

// Check Reg Image
if ($vbulletin->options['regimagecheck'] AND $vbulletin->options['regimagetype'])
{
    require_once(
DIR '/includes/functions_regimage.php');
    if (!
verify_regimage_hash($vbulletin->GPC['imagehash'], $vbulletin->GPC['imagestamp']))
    {
    
$userdata->error('register_imagecheck');
      }


But it doesn't work. I was able to add Sister Mary Sunshine no problem. Any clue?

Daniel 09-29-2007 05:46 AM

Quote:

Originally Posted by josiespencer (Post 1076355)
I couldn't find your original anchor point in register.php so I put it in the code just after referrer and before the image check. It looks like this:

PHP Code:

// check referrer
if ($vbulletin->GPC['referrername'] AND !$vbulletin->userinfo['userid'])
{
$userdata->set('referrerid'$vbulletin->GPC['referrername']);
}

//-------------------------------------------------- 
// check username does not contain UNWANTED characters 
if (preg_match('/[^a-zA-Z0-9\_]+/'$_POST['username'])) 

    
//eval(print_standard_error('error_username_semicolon')); 
    
eval('$errors[11] = "' fetch_phrase('username_invalidchars'PHRASETYPEID_ERROR) . '";'); 

//-------------------------------------------------  

// Check Reg Image
if ($vbulletin->options['regimagecheck'] AND $vbulletin->options['regimagetype'])
{
    require_once(
DIR '/includes/functions_regimage.php');
    if (!
verify_regimage_hash($vbulletin->GPC['imagehash'], $vbulletin->GPC['imagestamp']))
    {
    
$userdata->error('register_imagecheck');
      }


But it doesn't work. I was able to add Sister Mary Sunshine no problem. Any clue?

Bump. Anyone? :p


All times are GMT. The time now is 09:24 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01335 seconds
  • Memory Usage 1,844KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (9)bbcode_php_printable
  • (6)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (35)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete