============================================================================================================================
Modification Name: Username/Email Registration Checks

Version: 1.0

Author: GuldantheWarlock (GuldantheWarlock@xmbgarage.com)

Description:
This modification will put checks on the registration form to inform the user if the username and email are available and if the username contains any invalid characters.

Supported Version: XMB 1.9.5 SP1

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

Author Note:
You downloaded this modification from XMBGarage.com, the #1 source for XMB related downloads.
Please visit http://www.xmbgarage.com/ for support.

Please backup your files before installing this modification.
Neither XMB Garage nor the author can be held responsible if your board stops functioning properly due to you installing this modification.
============================================================================================================================
=======
Step 1:
=======
================
Edit File: header.php
================
==========
Find Code:
==========

$action != 'coppa'

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

$action != 'coppa' && $action != 'regcheck'

============================================================================================================================
=======
Step 2:
=======
=================
Edit File: member.php
=================
==========
Find Code:
==========

} elseif ($action == 'reg') {

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

// Username/Email Registration Checks Mod Begin
} elseif ($action == 'regcheck') {
    $do = isset($do) ? $do : '';
    $input = isset($input) ? addslashes($input) : '';
    if ($input == '' && $do != 'js') {
        echo 'no-input';
        exit;
    }

    switch($do) {
        case 'username':
            $query = $db->query("SELECT COUNT(uid) FROM $table_members WHERE username='$input'");
            if ((int)$db->result($query, 0) === 1) {
                echo 'taken';
                exit;
            }
            $db->free_result($query);
            
            $badchars = array('<', '>', '|', '"', '[', ']', '\\', ',', '@', '\'', ' ');
            foreach($badchars as $needle) {
                if (false !== strpos($input, $needle)) {
                    echo 'bad-chars';
                    exit;
                }
            }

            if (strlen($input) < 3) {
                echo 'too-short';
                exit;
            }

            if (strlen($input) > 32) {
                echo 'too-long';
                exit;
            }

            echo 'available';
            break;

        case 'email':
            if ($SETTINGS['doublee'] == 'on') {
                $query = $db->query("SELECT COUNT(uid) FROM $table_members WHERE email='$input'");
                if ($db->result($query, 0) > 0) {
                    echo 'in-use';
                    exit;
                }
                $db->free_result($query);
            }

            if (!preg_match('/^([a-zA-Z0-9]{1})+([a-zA-Z0-9_-])*@([a-zA-Z0-9]{1})+([a-zA-Z0-9_-])*\.([a-zA-Z\.])+?$/', $input)) {
                echo 'invalid-email';
                exit;
            }

            echo 'valid';
            break;

        case 'password':
            $input2 = isset($input2) ? $input2 : '';
            if (md5(trim($input)) === md5(trim($input2))) {
                echo 'match';
                exit;
            }

            echo 'no-match';
            break;

        case 'js':
            $output = array();
            $lnvars = array(
                'pwnomatch' => $lang['pwnomatch'],
                'invalid_chars' => $lang['arc_invalid_chars'],
                'username_taken' => $lang['arc_username_taken'],
                'username_short' => $lang['arc_username_too_short'],
                'username_long' => $lang['arc_username_too_long'],
                'email_taken' => $lang['arc_email_taken'],
                'email_invalid' => $lang['arc_email_invalid']
            );

            foreach($lnvars as $key => $val) {
                $output[] = 'Reg.Lang[\''.$key.'\'] = "'.$val.'";';
            }

            echo implode("\n", $output);
            break;
    }
    exit;
// Username/Email Registration Checks Mod End
    
============================================================================================================================
=======
Step 3:
=======
=======================
Edit File: lang/English.lang.php
=======================
========================
Add To End Of File Before  ?>
========================

// Username/Email Registration Checks Mod Begin
$lang['arc_username_taken'] = 'Username is already in use';
$lang['arc_invalid_chars'] = 'Username contains invalid characters';
$lang['arc_username_too_short'] = 'Too Short!';
$lang['arc_username_too_long'] = 'Too Long!';
$lang['arc_email_taken'] = 'E-Mail is already in use';
$lang['arc_email_invalid'] = 'Invalid E-Mail!';
// Username/Email Registration Checks Mod End

============================================================================================================================
=======
Step 4:
=======
===============================
Go To Administration Panel --> Templates
===============================
=====================
Edit Template: member_reg
=====================
==========
Find Code:
==========

<form method="post" action="member.php?action=reg">

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

<script type="text/javascript" src="./include/regcheck.js"></script>
<script type="text/javascript" src="./member.php?action=regcheck&do=js&dummy=$onlinetime"></script>
<form action="member.php?action=reg" id="reg" name="reg" method="post">

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

<input type="text" name="username" size="25" maxlength="25" />

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

<input type="text" name="username" size="25" maxlength="25" onchange="Reg.checkUsername(this.value);" />&nbsp;<span id="username-status"></span>

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

<input type="text" name="email" size="25" value="" />

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

<input type="text" name="email" size="25" value="" onchange="Reg.checkEmail(this.value);" />&nbsp;<span id="email-status"></span>

============================================================================================================================
=======
Step 5:
=======
===============================
Go To Administration Panel --> Templates
===============================
=============================
Edit Template: member_reg_password
=============================
==========
Find Code:
==========

<input type="password" name="password" size="25" />

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

<input type="password" name="password" size="25" onchange="Reg.checkPasswords();" />&nbsp;<span id="password-status"></span>

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

<input type="password" name="password2" size="25" />

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

<input type="password" name="password2" size="25" onchange="Reg.checkPasswords();" />&nbsp;<span id="password2-status"></span>

============================================================================================================================
=======
Step 6:
=======

Upload the file "regcheck.js" from the Contents folder to your forum's include folder.

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