FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum Development » Bug Reports » Register.php rejecting email
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Register.php rejecting email [message #1395] Thu, 11 April 2002 21:12 Go to next message
TimothyB is currently offline  TimothyB   United States
Messages: 2
Registered: April 2002
Karma: 0
Junior Member
We ran into a problem on one of our test machines here. Everytime a user would try to register, it would reject perfectly valid email addresses. I tracked this down to email.inc in the forum_data/include directory. I also found that the second regex does not seem to operate correctly in php. Works fine in perl. Was able to fix the offending regex by replacing the function used. The posix regex function returns a different answer than the perl regex function. So, with little to do, here is the diff:


@@ -21,7 +21,14 @@

function validate_email($email)
{
- if (eregi("(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)", $email) || !eregi ("^.+\@(\[?)[-_a-zA-Z0-9\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$", $email)) {
+/* Lines commented out to correct problem in register.php
+*
+* if (eregi("(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)", $email) || !eregi ("^.+\@(\[?)[-a-zA-Z0-9\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$", $email)) {
+*
+* Commented regex is BROKEN. Second regex of parse returns opposite
+* value of actual. Changed to perl regex matching.
+*/
+ if (eregi("(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)", $email) || !preg_match("/^.+\@[-_a-zA-Z0-9\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})$/" ;, $email)) {
return 1;
}
else {


This was with the new v1.2.4.

Regards,
Tim
Re: Register.php rejecting email [message #1398 is a reply to message #1395] Thu, 11 April 2002 21:56 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
Thank you for the patch I'll do a few tests and if all goes well it'll go into the CVS.

FUDforum Core Developer
Re: Register.php rejecting email [message #1399 is a reply to message #1398] Thu, 11 April 2002 22:08 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
After playing with regex and reading email RFCs

I belive that this should be a good check for email validity:


return !preg_match('!([-_A-Za-z0-9\.]+)\@([-_A-Za-z0-9\.]+)\.([A-Za-z0-9]{2,4})$!' , $email);


This also fixes a small bug in the old code (your change also has it) which dissalows emails from new domain types like .info

I will do further testing, but if you can please see if this function works fine with the emails that you have.


FUDforum Core Developer
Re: Register.php rejecting email [message #1400 is a reply to message #1395] Thu, 11 April 2002 22:25 Go to previous messageGo to next message
TimothyB is currently offline  TimothyB   United States
Messages: 2
Registered: April 2002
Karma: 0
Junior Member
Perfect, works beautifully. I'm sorry I didn't have time to try and trim the code, been a bit pressed for time today.

Regards,
Tim
Re: Register.php rejecting email [message #29655 is a reply to message #1395] Sat, 07 January 2006 14:05 Go to previous messageGo to next message
geekmug is currently offline  geekmug   United States
Messages: 5
Registered: January 2006
Karma: 0
Junior Member
I'm gonna drudge this back up rather than start a new topic. The current validate_email function is still incomplete. In particular, I noticed that it does not support a '+' in the local-part. I did a brief amount of research into finding a fully RFC compliant function and ran across http://www.ilovejackdaniels.com/php/email-address-validation/.

function validate_email($email)
{
	// Orignally by Dave Child, 2004 (http://www.ilovejackdaniels.com/php/email-address-validation/)

	// First, we check that there's one @ symbol, and that the lengths are right
	if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
		// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
		return true;
	}
	// Split it into sections to make life easier
	$email_array = explode("@", $email);
	$local_array = explode(".", $email_array[0]);
	for ($i = 0; $i < sizeof($local_array); $i++) {
		if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
			return true;
		}
	}
	if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
		$domain_array = explode(".", $email_array[1]);
		if (sizeof($domain_array) < 2) {
			return true; // Not enough parts to domain
		}
		for ($i = 0; $i < sizeof($domain_array); $i++) {
			if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
				return true;
			}
		}
	}
	return false;
}


//edited to invert the boolean logic (true = invalid, instead of true = valid).

[Updated on: Sat, 07 January 2006 14:13]

Report message to a moderator

Re: Register.php rejecting email [message #29685 is a reply to message #29655] Mon, 09 January 2006 16:10 Go to previous message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
The e-mail validator was adjusted to allow for + and provide a more robust validation process. You can find the patch here:
http://cvs.prohost.org/c/index.cgi/FUDforum/chngview?cn=7512


FUDforum Core Developer
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Error Log Viewer aborts
Next Topic: Empty Language list on Template Set Selection
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Jun 02 01:49:54 GMT 2024

Total time taken to generate the page: 0.04096 seconds