Hi,

I am on Drupal 6.x and I am using AntiSpam.

However what I want to do is prevent users (bots) from registering when an email address coming from a provider hosted in a particular country is used. For example "example.com".

So anyone entering "fdE764bX @ example.com" or "xb743bxjm @ example.com" should not be allowed to register at all. It shouldn't even go to the blocked section. The access should simply be denied. I am so sick of receiving these bogus registrations, I am ready to block entire service providers.

Is this possible? If not, perhaps I should seek my solution in the .htaccess file?

Comments

abhijeet sandil’s picture

You can do it using form alter and change validation function of user module
i.e function user_validate_name($name)

Here you can simply add your condition, that's it.

Mark_J’s picture

Thank you, thank you! You pointed me at the right direction. The function I need to modify is actually function user_validate_mail($mail) since I want to check for an email address and I can use the substr function to chop the string and return a value! I am about to try it out :)

Mark_J’s picture

It works! Thank you! I will ban so many spammer hosts and will save a copy of my mod so when I upgrade Drupal I can restore things.

Here is a sample code:

  if (substr($mail, strlen($mail) - 7, 7) == '1234567') return t('1234567 is banned, sorry :( You have to specify a different email provider');

1234567 is just an example here as I don't want to bad-mouth/offend anyone.

Thank you! :)

WorldFallz’s picture

Why not just do this at admin/user/rules? what am i missing?

Mark_J’s picture

Ok I just saw that but looks like a tedious job!

I actually did something much more efficient!! :)

First, I got this file: http://compuweb.com/url-domain-bl.txt

Then, I wrote a simple function in user.modules. The idea is to compare each line in the the spamlist file against the entered email address and check whether the current line in the file is contained within the user entered email address string.


function user_validate_bogus_email($mail) 
{
	
	// reads an entire file and stores it into an array so each line of the file is 
	// stored into a new element in $spamlist_array. 
	/* 
		$spamlist_array[0] = 'This is line 1';
		$spamlist_array[1] = 'This is line 2';
	*/
	$spamlist_array = file("http://example.com/spamlist.txt");

	// iterates till the end of the file where each element of the array is represented as
	// $line_num and the actual value as $value
	/*
		$spamlist_array[$line_num];
	*/
	foreach ($spamlist_array as $line_num => $value) 
	{
		// we want to check whether the current line ($value) is in $mail
		// we are not simply checking for $value because it has some type of character that makes the strpos()
		// function fail (most probably the new line character)
		$realvalue  = substr($value, 0, strlen($value) - 1);	// string to search in, start_pos, length
		$pos = strpos($mail, $realvalue);

		if ($pos === false) 
        {
             // do something if you want
		} 
		else 
		{
			return t('The email address you have entered is banned.<br />If you believe this is caused due to an error, please contact us.');
		}
	}	
}

Then in user_validate_mail, at the very bottom I added:

  else { 
	return user_validate_bogus_email($mail);
  }

So my entire function looks like this:

function user_validate_mail($mail) {
  if (!$mail) return t('You must enter an e-mail address.');
  if (!valid_email_address($mail)) {
    return t('The e-mail address %mail is not valid.', array('%mail' => $mail));
  }
  else { 
	return user_validate_bogus_email($mail);
  }
}

Ok, I know it's a bad practice to mess around with the Drupal modules but at the moment, I don't know how to turn this into a module or an override (haven't RTFMed/Googled enough (links are more than welcome :D) ).

WorldFallz’s picture

ah... that's different than what I thought you were asking for. You can easily add rules with masks so I don't find it particularly tedious, but there's also http://drupal.org/project/httpbl that works with the honeypot bl which is constantly kept updated.

Mark_J’s picture

That looks like a good module. Thanks for that. I'd still keep my spamlist though. In the last 4 hours I have only received one registration but I can't work out if's real or not. The domain is very real and legit but the user name is dodgy. I approved it and will monitor its activities and if it disappoints, I will just add it to my spam list at the end of the file.