forum.coppermine-gallery.net

Support => cpg1.5.x Support => cpg1.5 miscellaneous => Topic started by: fmk on January 02, 2011, 02:29:42 am

Title: Blocking "User Creation" with special characters and spaces in "Username"?
Post by: fmk on January 02, 2011, 02:29:42 am
Hi Guys,

A newbie + no programmer.

I need help with blocking "User Creation" with special characters and spaces in Usernames. I have edited text instructions in lang/english.php accordingly but want such attempts to be prohibited.

http://igallery.khanz.net

Thanks in advance.
Title: Re: Blocking "User Creation" with special characters and spaces in "Username"?
Post by: Αndré on January 03, 2011, 09:19:50 am
What shall happen if you detect unwanted characters? Do you want to automatically replace them? Do you want to display an error message? Which characters to you want to allow?
Title: Re: Blocking "User Creation" with special characters and spaces in "Username"?
Post by: fmk on January 03, 2011, 10:51:33 am
Allowed characters - Users must register with either "firstname.lastname" or "firstname" or "lastname. I want a-z allowed and No spaces, and special characters like hyphen, underscores, etc. My users are able to register with a space in the user name.

Q-What shall happen if unwanted characters are detected?
A-Page should return an error asking user for correction. Form data should not be lost though.

Q-Do you want to automatically replace them?
A-Its a nice idea, but users may get confused, so No.
Title: Re: Blocking "User Creation" with special characters and spaces in "Username"?
Post by: Αndré on January 03, 2011, 11:15:44 am
Open register.php, find
Code: [Select]
    if (utf_strlen($user_name) < 2) {
        $error .= '<li style="list-style-image:url(images/icons/stop.png)">' . $lang_register_php['username_warning2'] . '</li>';
    }
and replace with
Code: [Select]
    if (utf_strlen($user_name) < 2) {
        $error .= '<li style="list-style-image:url(images/icons/stop.png)">' . $lang_register_php['username_warning2'] . '</li>';
    } elseif (preg_match('/[^A-Za-z]/', $user_name)) {
        $error .= '<li style="list-style-image:url(images/icons/stop.png)">' . 'Username must only contain a-z' . '</li>';
    }
Title: Re: Blocking "User Creation" with special characters and spaces in "Username"?
Post by: fmk on January 04, 2011, 01:00:32 am
Works great. Thanks a lot Andre.