============================================================================================================================
Modification Title: Validate Email Address v1.1

Author: John Briggs

Last Updated: 04-17-10

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

Supported Version: XMB 1.9.5 SP1

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

License Note: This modication is released under the GPL License v3. A copy is provided with this software package.

Author Note:
For security purposes, Please Check: http://www.xmbgarage.com for the latest version of this modication.
Downloading this modication from other sites could cause malicious code to enter into your XMB Forum software.
As such, XMBGarage.com will not offer support for modications not at our web site.
============================================================================================================================
=======
Step 1:
=======
=================
Edit File: memcp.php
=================
==========
Find Code:
==========

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

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

        // Validate Email Address Mod Begin
        $email = isset($_POST['newemail']) ? checkInput($_POST['newemail'], '', '', 'javascript', false) : '';
        // Validate Email Address Mod End

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

        $db->query("UPDATE $table_members SET $pwtxt

===============
Add Code Above:
===============

        // Validate Email Address Mod Begin
        $email = trim($email);
        $efail = false;
        $query = $db->query("SELECT * FROM $table_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 $table_members SET email = '$email', password = '$newmd5pass' WHERE username = '$member[username]'");
            $db->query("DELETE FROM $table_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);
        }
        // Validate Email Address Mod End

============================================================================================================================
=======
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 Administration Panel --> Templates
===============================
=======================
Edit Template:  memcp_profile
=======================
==========
Find Code:
==========

<tr>
<td bgcolor="$altbg1" width="22%" class="tablerow">$lang[textemail]</td>
<td bgcolor="$altbg2" class="tablerow"><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>

============================================================================================================================
Enjoy!