[drupal-devel] [feature] Better validation of new users email address when creating account

budda drupal-devel at drupal.org
Wed Feb 23 01:45:59 UTC 2005


 Project:      Drupal
 Version:      4.5.2
 Component:    user.module
 Category:     feature requests
 Priority:     normal
 Assigned to:  Anonymous
 Reported by:  budda
 Updated by:   budda
 Status:       patch

it *may* be more helpful to move the MX record checking in to the common
valid_email_address() function instead? This would ensure other modules
validating email addresses could gain the same functionality.


budda



Previous comments:
------------------------------------------------------------------------

February 23, 2005 - 01:26 : budda

Working with the user.module of 4.5.2 distribution I amended the
user_validate_mail() function to provide additional checking for a new
user.
This was inspired by the constant bounced emails I was getting each day
from new users mistyping their email address.
Sorry that the code is not in patch form. The following code should be
placed in user.module :-
function _user_check_dnsrr($maildomain, $rectype = 'MX')
{
  if(!empty($maildomain)) {
    if(function_exists('checkdnsrr')) {
      return checkdnsrr($maildomain, $rectype);
    } else {
      exec("nslookup -type=$rectype $maildomain", $result);
      foreach ($result as $line) {
        if(eregi("^$maildomain",$line)) {
          return true;
        }
      }
      return false;
    }
  }
  return false;
}
function user_validate_mail($mail) {
  if (!$mail) return t('You must enter an e-mail address.');
  list($username, $maildomain) = split("@", $mail);
  if (!valid_email_address($mail) || !_user_check_dnsrr($maildomain,
"MX")) {
    return t('The e-mail address %mail is not valid.', array('%mail' =>
"<em>$mail</em>"));
  }
}
I have been using the above on
http://www.bargainspy.co.uk/user/register without problem for a day
now. Another step in the direction of helping users hide their general
stupidity!


-- 
View: http://drupal.org/node/17780
Edit: http://drupal.org/project/comments/add/17780





More information about the drupal-devel mailing list