coppermine-gallery.com/forum

Support => cpg1.4.x Support => Older/other versions => cpg1.4 miscellaneous => Topic started by: pawelfoto on December 15, 2009, 09:41:40 PM

Title: How to block special charakters in username?
Post by: pawelfoto on December 15, 2009, 09:41:40 PM
Hello,


I have a problem with the users whose names contain special  and unusual characters like:  , ą, ó, ł and underscore.

Problem is, because username is passing to some script, and that script does not recognize these characters.

It is possible to rework scirpt so as to block these characters?

Title: Re: How to block special charakters in username?
Post by: pawelfoto on December 15, 2009, 09:42:19 PM
www.pawelfoto.com
Title: Re: How to block special charakters in username?
Post by: pawelfoto on December 15, 2009, 09:44:13 PM
Sorry, i am absentminded.  I would like block it on registration page - register.php
Title: Re: How to block special charakters in username?
Post by: Joachim Müller on December 16, 2009, 08:43:04 AM
Quote from: pawelfoto on December 15, 2009, 09:44:13 PM
I would like block it on registration page - register.php
Edit register.php, find function check_user_info(&$error)and add your custom validation code, e.g. afterif (utf_strlen($user_name) < 2) $error .= '<li>' . $lang_register_php['err_uname_short'];in a new line you might add something likeif (!eregi("^[0-9a-zA-Z]$", $user_name)) $error .= '<li>Illegal character in username' ;

Quote from: pawelfoto on December 15, 2009, 09:41:40 PMProblem is, because username is passing to some script, and that script does not recognize these characters.
Better option: edit that other script to allow special characters.
Title: Re: How to block special charakters in username?
Post by: pawelfoto on December 16, 2009, 10:59:26 AM
 Hi
There is somethong wrong .. :-[

after adding the lines of code are blocked all the characters... Even if I want to register a user "abcd"  I gets message - Illegal character in username.
Title: Re: How to block special charakters in username?
Post by: VEGA on December 16, 2009, 04:27:26 PM
if (!eregi("^[*-@-:-']$", $user_name)) $error .= '<li>Illegal character in username' ;

I included the characters that do not want them to be used for register. Not know if I can help you!
Title: Re: How to block special charakters in username?
Post by: pawelfoto on December 16, 2009, 04:43:18 PM
Quote from: VEGA on December 16, 2009, 04:27:26 PM
if (!eregi("^[*-@-:-']$", $user_name)) $error .= '<li>Illegal character in username' ;

I included the characters that do not want them to be used for register. Not know if I can help you!

That's clever  :)

I need to check it.
Title: Re: How to block special charakters in username?
Post by: Joachim Müller on December 16, 2009, 05:53:08 PM
Better to revert the logic by removing the exclamation mark: you probably haven't thought of all harmfull chracters. A whitelist is better than a blacklist in this aspect.
Title: Re: How to block special charakters in username?
Post by: pawelfoto on December 16, 2009, 06:29:49 PM
Finally I made it in this way:
if (eregi("([^abcdefghijklmnopqrstuvwxyz0123456789])", $user_name)) $error .= '<li>Nieprawidłowy znak w nazwie użytkownika.' ;

This meets my expectations in 100%
Title: Re: How to block special charakters in username?
Post by: phill104 on December 16, 2009, 06:56:13 PM
http://php.net/manual/en/function.eregi.php
Title: Re: How to block special charakters in username?
Post by: Joachim Müller on December 17, 2009, 07:35:15 AM
...and what exactly is so different about your way? What's the use of if (eregi("([^abcdefghijklmnopqrstuvwxyz0123456789])", $user_name)) $error .= '<li>Nieprawidłowy znak w nazwie użytkownika.' ;in comparison toif (eregi("([^a-z0-9])", $user_name)) $error .= '<li>Nieprawidłowy znak w nazwie użytkownika.' ;