News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Filtering usernames during registration page

Started by MrPython, August 26, 2023, 03:23:52 PM

Previous topic - Next topic

MrPython

Many users write usernames that are generally unreadable or indecent. It is still possible to deal with obscene names by filtering names, but with a meaningless set of letters and numbers, it is difficult. Perhaps for someone it is not important, but I do not want to communicate with the genitals))

I decided to apply name filtering on the registration page.
Reserved names do not use a mask, or regular expressions. I would like to add this to the code, maybe then make a modification.

And this is how I added the name validation function
File Register.php
Line number 25
Code (php) Select
// Chek username
function bad_username($username)
{
$pattern = '/^[A-Za-z][A-Za-z]*\d*$/';
return preg_match($pattern, $username);
}

But I can't use it properly.

Here is an example how I tried to use.
Line 246
Code (php) Select
/* $context += array(
'username' => isset($_POST['user']) ? $smcFunc['htmlspecialchars']($_POST['user']) : '',
'email' => isset($_POST['email']) ? $smcFunc['htmlspecialchars']($_POST['email']) : '',
'notify_announcements' => !empty($_POST['notify_announcements']) ? 1 : 0,
);*/

$newuser = array(
'username' => isset($_POST['user']) ? $smcFunc['htmlspecialchars']($_POST['user']) : '',
'email' => isset($_POST['email']) ? $smcFunc['htmlspecialchars']($_POST['email']) : '',
'notify_announcements' => !empty($_POST['notify_announcements']) ? 1 : 0,
);
if (!empty($newuser['username']) && (bad_username($newuser['username']))  )
$context = $context + $newuser;
}
else {
$newuser['username'] = '';
$context = $context + $newuser;
}


There were other variants of the code, but they did not work either.

Kindred

You're trying to control a social issue through technical means.
It's doomed to failure even if you got it working.

I have been running forums for 30+ years and I have never had a problem with user names that you describe.
Сл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."

MrPython

Can I set my own rules for my forum? Or do I need to ask someone for permission? This is not the first day I have been leading forums, what does this change? There are moderators, but why do you need empty work if you can immediately filter out the word "f-o-r-u-m-s-u-k-s"?

This is a technical issue.
One way or another, I will make filtering names work with regular expressions, since the basic filter does not cope with the tasks.
I see two ways to extend the "Set Reserved Names" filtering options with regular expressions. Or an easier way - filtering the input field.
If you can help please help me, I think this is a needed feature.

Sesquipedalian

If you download and inspect the code for my Spoof Detector mod, you will see how to add new capabilities to the reserved name system. If you follow the approach I used in that mod, you should be able to implement the new abilities you want. (You might also want to install Spoof Detector; it will reduce the number of ways for people to bypass your filters.)

That said, Kindred is right. What you are trying to do will only result in an escalating "arms race" between you and the hostile users. Every time you add a new regular expression to your list of filters, they'll just come up with a different name to bypass it. Then you will need to write another regular expression to block that and you will still need to deal with the problematic name in the same way that you already do now. Rather than saving yourself time, you may very well end up wasting more of it.

You will probably do better if you simply require admin approval for new registrations and configure your permissions so that people can't edit their own display names.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

MrPython

We ban spammers and haters. I'll take a look at your code, thanks!

Kindred

Stop spammers from even registering in the first place....

As for banning haters -- again,  it's a losing battle on your side,  if they really care... because overcoming a ban is a 2 minute action if the banned person has any clue how the interwebs work.

Obviously,  it's your forum...  but it's a good idea to take notes from those of us with experience
Сл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."

MrPython

I just want to streamline the usernames a bit. There are not so many haters, sometimes schoolchildren attack during the holidays, but we have a friendly team, we are like bearded bikers with our own interests.

Advertisement: