Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Enhancement] Disallowed user and mails with regexp
#1
It could be an interesting feature to use regexp for disallowing usernames and emails.

Short example: I had yesterday 3 spammers, with username me886me, tu886tu and we886we, and their mail was <username>@outlook.com
I can't forbid *@outlook.com and I can't ban *886*, but I probably can ban ([a-z]{2})\d{3}\1 as username
Tchat en français
Do not ask me help through PM or Discord

Reply
#2
That's sounds pretty good and it seems too logical...... I also want this.
Reply
#3
Looking @ is_banned_username() and is_banned_email(), it could be quite easy to do.
I've 2 proposals:
- use a special char at the beginning of the mask
- add a checkbox (and a field in mybb_banfilters)

And modification in function should be something like:
/**
 * Checks if a username has been disallowed for registration/use.
 *
 * @param string $username The username
 * @param boolean $update_lastuse True if the 'last used' dateline should be updated if a match is found.
 * @return boolean True if banned, false if not banned
 */
function is_banned_username($username, $update_lastuse=false)
{
	global $db;
	$query = $db->simple_select('banfilters', 'filter, fid, regex', "type='2'");
	while($banned_username = $db->fetch_array($query))
	{
		// Make regular expression * match
		if ($banned_username['regex']==1)
		{
			$pattern = "#^" . $banned_username['filter'] . "$#i";
		}
		else
		{
			$banned_username['filter'] = str_replace('\*', '(.*)', preg_quote($banned_username['filter'], '#'));
			$pattern = "#(^|\b){$banned_username['filter']}($|\b)#i";
  		}
		if(preg_match($pattern, $username))
		{
			// Updating last use
			if($update_lastuse == true)
			{
				$db->update_query("banfilters", array("lastuse" => TIME_NOW), "fid='{$banned_username['fid']}'");
			}
			return true;
		}
	}
	// Still here - good username
	return false;
}
The creation of $pattern is only because if we need back references, we must not have capture group at the beginning.
Tchat en français
Do not ask me help through PM or Discord

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)