News:

Want to get involved in developing SMF? Why not lend a hand on our GitHub!

Main Menu

Restrict/Prevention of non English character in registeration

Started by Mr. Pedram, February 18, 2013, 06:42:55 AM

Previous topic - Next topic

Mr. Pedram

Hey SMFers!
I want to prevention of non English username registeration, because my forum is persian and i don't want user have a non English username (Like: Persian or Arabic Names) for many reason! is there solution? or a MOD by any chance!?

Thanks
My Modifications:
» Loading For SMF
» Buddies Block
» Redirect Links
» Birthdate On Registration
» PM Warning
» Instagram
» Add Table,Td,Tr Button
» Search Topic & Board Button
Browse All...

kat

You could use the "Reserved names" thing. But, you'd need to include a LOT of names. Plus, of course, many English people have non-English names.

I somehow doubt that such a thing would be practicable, Mr. P.

Sorry an' all that.

MrPhil

When you say "non-English username", do you mean that you want to restrict the character set for names to, say, ASCII? That could be done -- there may even be a mod already out there for that (I recall seeing it discussed before). With a little coding, it would be possible to restrict the character set used when selecting a name to anything you want, even binary digits!

Mr. Pedram

Quote from: MrPhil on February 18, 2013, 09:30:45 AM
When you say "non-English username", do you mean that you want to restrict the character set for names to, say, ASCII? That could be done -- there may even be a mod already out there for that (I recall seeing it discussed before). With a little coding, it would be possible to restrict the character set used when selecting a name to anything you want, even binary digits!


Exactly, sorry i didn't know how to describe my request. i want to restrict the character set.
For example an invalid username, like persian, arabic, Russian, chinese, hindi characters and etc...

فارسی
русский

and other Non-English languages.
but i only want to restrict persian charachter. if already a MOD for this exist, or someone can help for coding, please let me know.

Thanks
My Modifications:
» Loading For SMF
» Buddies Block
» Redirect Links
» Birthdate On Registration
» PM Warning
» Instagram
» Add Table,Td,Tr Button
» Search Topic & Board Button
Browse All...

Kindred

I don't see a mod for it...   I'd suggest posting a request in the mod requests board, since this is not actually a support issue.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Mr. Pedram

You right, would someone move this topic to mod request board! or i'll make a new topic there..
My Modifications:
» Loading For SMF
» Buddies Block
» Redirect Links
» Birthdate On Registration
» PM Warning
» Instagram
» Add Table,Td,Tr Button
» Search Topic & Board Button
Browse All...

MrPhil

If no one has a mod for this, it looks like it should be pretty simple to restrict the alphabet for names. In Sources/Subs-Members.php, look for function isReservedName. In the middle of it, look for
            // Characters we just shouldn't allow, regardless.
and add just before that line:
            // Restrict the name's alphabet (e.g., ASCII letters, digits, and a few punctuation marks)
            if (preg_match('~[^A-Z0-9 _-]~i', $checkName)) {
               if ($fatal)               
                    fatal_lang_error('name_invalid_character', 'password', array($checkName));
               else
                    return true;
            }

Be sure to check this on a UTF-8 system (I haven't tested it). It's possible that it won't always work right, but I would think that even if a UTF-8 name string is seen as a string of odd bytes, that at least one byte should trigger the refusal. This might not work if you expand the "ALLOWED" list in the pattern to include non-ASCII Latin-1 characters, as they will have the wrong encoding anyway for UTF-8. The ALLOWED list here is A-Z, a-z (via the "i" ignore case switch), 0-9, blank, underscore (_), and hyphen (-). Add or delete ASCII character set characters as desired (they should be the same in all reasonable encodings).

I have not checked if any place does not use isReservedName(), and should. Nor have i checked if any place uses this function for other purposes, and you would not want it to restrict the alphabet there!

P.S. Note to developers: I see this function uses preg_replace with the "e" switch. That ability is going away soon (deprecated).

Mr. Pedram

Thanks for it,
i get error when paste this snip before that line, something is wrong i think.
My Modifications:
» Loading For SMF
» Buddies Block
» Redirect Links
» Birthdate On Registration
» PM Warning
» Instagram
» Add Table,Td,Tr Button
» Search Topic & Board Button
Browse All...

MrPhil

Oopsie. Missing a ). Previous post updated. I told you it wasn't tested!

Mr. Pedram

Quote from: MrPhil on February 18, 2013, 02:29:46 PM
Oopsie. Missing a ). Previous post updated. I told you it wasn't tested!



Thanks man, it works perfectly. it's exactly what i wanted.
much appreciated.
do you decide to make this as a MOD?
No doubt, it will be a useful MOD for everyone, plus it might stop some spammer with non-english usernames.

My Modifications:
» Loading For SMF
» Buddies Block
» Redirect Links
» Birthdate On Registration
» PM Warning
» Instagram
» Add Table,Td,Tr Button
» Search Topic & Board Button
Browse All...

MrPhil

I wasn't planning to make a mod, as it's so tiny, and you might want to adjust the alphabet allowed. Maybe I'll just put it on my site and let people install it themselves. It would also be nice to test it a bit more (some day). Glad it helped you!

Advertisement: