Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

why cann't use Asian characters as a user' name ? Is there a solution ?

longnightlongnight New
edited November 2010 in Vanilla 2.0 - 2.8
why cann't use Asian characters to register a user name , such like "李国蛋" "张学友"or "わかった" ?

I hope my users can use Characters which their are more familiar than Latin words .

Is there a solution ?

My website is using UTF-8 database, welcome to visit: http://www.cnfood.tk

Vanilla 2 .

Tagged:

Comments

  • i also want to know....
  • i also want to know....
    I think it's a big important problem !

  • let it up ! need sb help ...
  • yu_tangyu_tang New
    edited December 2010
    3 steps.

    1)
    in vanilla\library\core\functions.validation.php
    Search ValidateUsername() function and change regexp pattern from
    '/^([\d\w_]{3,20})?$/si'
    to
    '/^([一-龠]|[ぁ-ん]|[ァ-ヴー]|[ a-zA-Z0-9_\-]|[ a-zA-Z0-9_―]){3,20}?$/u'
    Above pattern is for Japanese. So you should be wrote difference depending on your language.

    Now, you can use non-ascii characters for username.

    2)
    If you change username to non-ascii characters in profile, you may encounter 404 error after save and redirect.
    in vanilla\applications\dashboard\controllers\class.profilecontroller.php
    Search Edit() function and change redirect code from
    $this->RedirectUrl = Url('/profile/'.Gdn_Format::Url($User->Name));
    to
    $this->RedirectUrl = Url('/profile/'.$User->UserID.'/'.Gdn_Format::Url($User->Name));


    2010-12-16: another solution found.
    applications\dashboard\models\class.usermodel.php
    change
    $User = $this->SQL->Where('u.Name', $Username)->Get()->FirstRow();
    to
    $User = $this->SQL->Where('u.Name', urldecode($Username))->Get()->FirstRow();

    I edited this and found 中文用户名解决方案 - Vanilla Forums. lol

    Anyway, now 404 error has gone.

    3)
    In default, Vanilla count letters as ascii. Thus a non-ascii character is counted 2 or 3 length in UTF-8.
    That causes a problem about 20 chars max for username. You get over limit error with 10 or 7 chars non-ascii username.
    Once again in vanilla\library\core\functions.validation.php
    Search ValidateLength() function and change code from
    $Diff = strlen($Value) - $Field->Length;
    to
    $Diff = mb_strlen($Value, 'utf-8') - $Field->Length;

    That's it.

    One thing, I am an amateur in PHP. Actually I rent PHP dictionary from library yesterday because I know nothing.
    So I guess if Vanilla core developers allows only ascii for username, maybe they have the reasons. Don't trust this hack.
  • @yu_tang Thanks a lot !
    I'll try your method soon !
    But, change from
    '/^([\d\w_]{3,20})?$/si'
    to
    '/^([一-龠]|[ぁ-ん]|[ァ-ヴー]|[ a-zA-Z0-9_\-]|[ a-zA-Z0-9_―]){3,20}?$/u'

    How about Chinese,what should I apply ? 中文.
    or What's these code's name ? I'll search them to replace.
  • yu_tangyu_tang New
    edited December 2010
    @longnight You're welcome!
    How about Chinese,what should I apply ? 中文.
    Google pointed out...
    regex - PHP -Multibyte regular expression to remove all but chinese characters...please help - Stack Overflow

    so, maybe...

    '/^[\d\w_\x4E00-\x9FA5]{3,20}?$/u'

    Sorry, I didn't test it. It's just a thought.

    btw, non-ascii user name breaks @ link function in comments.
    I realized just now. I think we need more help or insensitivity.
  • oops....

    @yu_tang

    both these two hack can't use asian words ......

    change to
    '/^([一-龠]|[ぁ-ん]|[ァ-ヴー]|[ a-zA-Z0-9_\-]|[ a-zA-Z0-9_―]){3,20}?$/u'
    resules in any words(Asian and Latin ) to register fail .

    change to
    '/^[\d\w_\x4E00-\x9FA5]{3,20}?$/u'
    This time it still can't use Asian Characters to register , but Latins word was allowed .
  • Ok, another shot.
    try this.
    '/^[\d\w_\x{4E00}-\x{9FA5}]{3,20}?$/u'
  • longnightlongnight New
    edited December 2010

    http://vanillaforums.org/discussion/14112/中文用户名解决方案

    '/^([\d\w_\x80-\xff]{3,20})?$/si'

    this line worked. anyway ,thanks for your kind heart ,welcome to visit my forum:
    http://www.cnfood.tk/

    There still be some small promblems ;)
  • Congrats! @longnight
    There still be some small promblems ;)
    For functioning @mentions links with asian chars username, you'd better to check this.

    library/core/class.format.php
    $Mixed = preg_replace( '/(^|[\s,\.])@(\w{1,20})\b/i', //{3,20} '\1'.Anchor('@\2', '/profile/\\2'),

    Yes, another regexp pattern there. Good luck!
  • @yu_tang @longnight also there's #topic bug. and some small bugs in mobile mode.
    alt attribute of user's head image.
    modify regexp pattern or use urldecode() function will work.

    our forum is http://beta.neupioneer.com invitation register only.
  • It's a good thing you guys tested this. The devs should fix their code to make this possible out of the box. Applications like this one always support UTF8 "in theory", but not always in practice. ;)
Sign In or Register to comment.