Jump to content

Bogus User Filter


gcphost

Recommended Posts

I offer a free trial product and it tends to get those bogus 'asdf' users - im sure there is some other way to do this but the way I wanted to is simply writing my own hook.

 

This lets me define individual flags to match against, and how, im general - if it matches any of the 'bs' then out it goes.

 

 

<?php

function bad_var($val){
$bad=array();
$bad[]="asdf";
$bad[]="opk";
$bad[]="12345";
$bad[]="dfgh";
$bad[]="test";

foreach($bad as $b=>$d){
	if(preg_match("/$d/s", $val)) return true;
}
return false;
}

function BogusUser($vars) {
global $errormessage;
foreach($vars as $v => $r){
	if(bad_var($r)) $errormessage.="The field $v has an value that did not pass validation. Please change it and try again!<br>";
}
}

add_hook("ClientDetailsValidation",1,"BogusUser");

?>

 

Did lite testing, seems to work well - almost hard to go wrong but certainly if I did post back.

Link to comment
Share on other sites

I would also note this should probably have a case for the error and a case for the var checking to match the user input variables and to output the error in the correct language.

 

I didnt care - clearly - but if someone were to update it thatd be sweet :D

Link to comment
Share on other sites

Just to update that the last 2 days have been great! Those "asdf" users are totally gone, people now provide real and valid information almost all the time! I've added more filters - like a direct (not preg match) filter array to help with "lol lol" names, I am sure others get those too.

 

Using this with with some new order system changes and my custom programs to help sell licenses WHMCS is finally working out well for me, the hooks have paid off big time for me.

<?php

function bad_var($val){
$baddirect=array();
$baddirect[]="lol";
$baddirect[]="lol ";
$baddirect[]="lol lol";

$bad=array();
$bad[]="asdf";
$bad[]="opk";
$bad[]="12345";
$bad[]="dfgh";
$bad[]="test";
$bad[]="dsds";
$bad[]="afvbs";
$bad[]="aaa";
$bad[]="bbb";
$bad[]="aewqr";
$bad[]="acxzcz";
$bad[]="aasdsda";
$bad[]="sdaasd";
$bad[]="acxzcz";
$bad[]="asdasd";
$bad[]=" lol ";

foreach($bad as $b=>$d){
	if(preg_match("/$d/s", $val) || $d == $val) return true;
}
foreach($baddirect as $b=>$d){
	if($d == $val) return true;
}
return false;
}

function BogusUser($vars) {
global $errormessage;
foreach($vars as $v => $r){
	if(bad_var($r)) $errormessage.="The field $v has an value that did not pass validation. Please change it and try again!<br>";
}
}

add_hook("ClientDetailsValidation",1,"BogusUser");

?>

Link to comment
Share on other sites

  • 4 months later...
  • 5 weeks later...

Just wanted to share my improvements on this script, adding a role based email address filter, and also filtering the input more to account for changes in case and spacing, this hook now filters bad names like aSDF and aDMin@domain.com (role based address)

 

<?php

function bad_var($val){
$baddirect=array();
$baddirect[]="lol";
$baddirect[]="lol ";
$baddirect[]="lol lol";

$bad=array();
$bad[]="asdf";
$bad[]="opk";
$bad[]="qwerty";
$bad[]="12345";
$bad[]="dfgh";
$bad[]="test";
$bad[]="dsds";
$bad[]="dsf";
$bad[]="afvbs";
$bad[]="aaa";
$bad[]="bbb";
$bad[]="aewqr";
$bad[]="acxzcz";
$bad[]="aasdsda";
$bad[]="sdaasd";
$bad[]="acxzcz";
$bad[]="asdasd";
$bad[]="nostreet";
$bad[]="1234as";
$bad[]="root@";
$bad[]="admin@";
$bad[]="default@";
$bad[]="administrator@";
$bad[]="info@";
$bad[]="webmaster@";
$bad[]="sales@";
$bad[]="support@";
$bad[]="management@";
$bad[]=" lol ";

foreach($bad as $b=>$d){
	if(preg_match("/$d/s", $val) || $d == $val) return true;
}
foreach($baddirect as $b=>$d){
	if($d == $val) return true;
}
return false;
}

function BogusUser($vars) {
global $errormessage;
foreach($vars as $v => $r){
	if(bad_var(trim(strtolower($r)))) {
		if ($v == "email") $errormessage.="<li>Please use a personal email address, not a generic/root address.</li>";
		else $errormessage.="<li>The field $v has an invalid value. Please enter your correct information!</li>";
	}
}
}

add_hook("ClientDetailsValidation",1,"BogusUser");

?>

Link to comment
Share on other sites

Here is an updated array of role based addresses that mailchimp doesn't allow (see http://kb.mailchimp.com/article/what-role-addresses-does-mailchimp-specifically-block-from-bulk-importing/) :

	$roles = array('info@',
			'help@',
			'admin@',
			'biz@',
			'bizdev@',
			'support@',
			'faq@',
			'customerservice@',
			'press@',
			'sales@',
			'webmaster@',
			'abuse@',
			'postmaster@',
			'editor@',
			'hostmaster@',
			'investorrelations@',
			'jobs@',
			'marketing@',
			'media@',
			'noc@',
			'remove@',
			'request@',
			'root@',
			'security@',
			'spam@',
			'subscribe@',
			'usenet@',
			'users@',
			'uucp@',
			'www@',
			'news@',
			'enquiries@',
			'service@',
			'advertising@',
			'marketing@',
			'finance@',
			'accounting@',
			'billing@',
			'legal@',
			'jobs@',
			'hr@',
			'service@',
			'investors@',
			'board@',
			'ventas@');

Then in the check function, add in this foreach loop:

foreach($roles as $b=>$d){
	if(preg_match("/$d/s", $val) || $d == $val) return true;
}

Link to comment
Share on other sites

  • 2 months later...

Hi,

 

Can someone let the rest of us know what file needs to be modded for this mod to work ? Cheers.

 

This is an action hook.

So, you must create a new php file (name it as you want), insert the code inside this file and the upload it to your hooks directory (/your_installation_path/includes/hooks/).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated