Mod Title: Validate Email Address v1.1

Mod Author: John Briggs

Last Updated: 05-23-08

Mod Description:
This modification will log members out when they change their email address and sends them a new password.
This modification will ensure that only valid @ char characters are used in email address and prevents empty email addresses.
This modification will check to ensure that no one uses an email that is restricted in admin panel.

Supported Version: XMB 1.9.8 Engage Final SP2/SP3

Installation Note: Before adding this mod to your forum, you should back up all files related to this mod.

License Note: This mod is released under the GPL License.

Author Note:
For security purposes, Please Check: http://www.xmbxtreme.com for the latest version of this mod.
Downloading this mod from other sites could cause malicious code to enter into your XMB Forum software.
As such, XMBGarage.com will not offer support for mods not offered at our site.

Mod History:

11-25-04 - Version 1.0
- Initial release.

04-28-05 - Version 1.1
- Updated code and fixed a few bugs which were minor.

05-28-06 - Version 1.1
- Updated for 1.9.5 by: WormHole @ XMB Garage

05-23-08 - Version 1.1
- Updated for 1.9.8 by: WormHole @ XMB Garage

=======================================================================================================================
=======
Step 1:
=======

====================
Edit File: memcp.php
====================

==========
Find Code:
==========

        $email = $newemail ? checkInput($newemail, 'no', 'yes', 'javascript', false) : '';

==================
Replace Code With:
==================

        $email = isset($_POST['newemail']) ? checkInput($_POST['newemail'], '', '', 'javascript', false) : '';

==========
Find Code:
==========

            $pwtxt = '';
        }

===============
Add Code Below:
===============

        $email = trim($email);
        $efail = false;
        $query = $db->query("SELECT * FROM ".X_PREFIX."restricted");
        while ($erestrict = $db->fetch_array($query)) {
            if ($erestrict['case_sensitivity'] == 1) {
                if ($erestrict['partial'] == 1) {
                    if (strpos($email, $erestrict['name']) !== false) {
                        $efail = true;
                    }
                } else {
                    if ($email == $erestrict['name']) {
                        $efail = true;
                    }
                }
            } else {
                $t_email = strtolower($email);
                $erestrict['name'] = strtolower($erestrict['name']);

                if ($erestrict['partial'] == 1) {
                    if (strpos($t_email, $erestrict['name']) !== false) {
                        $efail = true;
                    }
                } else {
                    if ($t_email == $erestrict['name']) {
                        $efail = true;
                    }
                }
            }
        }
        $db->free_result($query);

        if ($efail) {
            error($lang['emailvaliderror1'], false);
        }

        if (empty($email) || false === strpos($email, "@")) {
            error($lang['emailvaliderror2'], false);
        }

        if ($email != $member['email']) {
            $newpass = '';
            $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
            mt_srand((double)microtime() * 1000000);
            $max = mt_rand(8, 12);
            for ($get = strlen($chars), $i = 0; $i < $max; $i++) {
                $newpass .= $chars[mt_rand(0, $get)];
            }

            $newmd5pass = md5(trim($newpass));
            $db->query("UPDATE ".X_PREFIX."members SET email = '$email', password = '$newmd5pass' WHERE username = '$member[username]'");
            $db->query("DELETE FROM ".X_PREFIX."whosonline WHERE username = '$member[username]'");

            $headers[] = "From: $bbname <$adminemail>";
            $headers[] = "X-Sender: <$adminemail>";
            $headers[] = 'X-Mailer: PHP';
            $headers[] = 'X-AntiAbuse: Board servername - '.$bbname;
            $headers[] = 'X-AntiAbuse: Username - '.$xmbuser;
            $headers[] = 'X-Priority: 2';
            $headers[] = "Return-Path: <$adminemail>";
            $headers[] = 'Content-Type: text/plain; charset=ASCII';
            $headers = implode("\r\n", $headers);

            altmail($email, '['.$bbname.'] '.$lang['textyourpw'], $lang['emailvalidpwis']."\n\n".$member['username']."\n".$newpass, $headers);
            $currtime = $onlinetime - (86400*30);
            put_cookie("xmbuser", $username, $currtime, $cookiepath, $cookiedomain);
            put_cookie("xmbpw", $newmd5pass, $currtime, $cookiepath, $cookiedomain);
        }

=======================================================================================================================
=======
Step 2:
=======

=================================
Edit File: /lang/English.lang.php
=================================

========================
Add To End Of File Above ?>:
========================

// Validate Email Address Mod Begin
$lang['emailvaliderror1'] = "Sorry, this e-mail is reserved/restricted by the board administrator. Please go back and try again.";
$lang['emailvaliderror2'] = "Sorry, you must use a valid e-mail address. Please go back and try again.";
$lang['emailvaliderror3'] = "Sorry, This e-mail address is already in use by another member. Please go back and try again.";
$lang['emailvalidpwis'] = "You have received this automatic e-mail because you have recently changed your e-mail address at $bbname. Your new password details are below.";
$lang['emailvalidmsg'] = "E-mail address must be valid.";
// Validate Email Address Mod End

=======================================================================================================================
=======
Step 3:
=======

================================================================
Go to admin panel -> templates -> edit template -> memcp_profile
================================================================

==========
Find Code:
==========

<tr class="tablerow">
<td bgcolor="$altbg1" width="22%">$lang[textemail]</td>
<td bgcolor="$altbg2"><input type="text" name="newemail" size="25" value="$member[email]" /></td>
</tr>

==================
Replace Code With:
==================

<tr class="tablerow">
<td bgcolor="$altbg1" width="22%">$lang[textemail]</td>
<td bgcolor="$altbg2"><input type="text" name="newemail" size="25" value="$member[email]" />&nbsp;$lang[emailvalidmsg]</td>
</tr>

=======================================================================================================================