Update on this code:
Replace lines 48-85 with this code, instead of the above:
// check for duplicate email address
$sql = "SELECT internalKey FROM ".$modx->getFullTableName("web_user_attributes")." WHERE email='$email'";
if(!$rs = $modx->db->query($sql)){
$output = webLoginAlert(WL_ERRONCHECKEMAIL.$email).$tpl;
return;
}
$limit = $modx->db->getRecordCount($rs);
if($limit>0) {
$row=$modx->db->getRow($rs);
if($row['internalKey']!=$id) {
$output = webLoginAlert(WL_EMAILINUSE).$tpl;
return;
}
}
if($email=='' || !preg_match("/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i", $email)){
$output = webLoginAlert("E-mail address doesn't seem to be valid!").$tpl;
return;
}
//verify email confirm
if($email != $modx->db->escape($_POST['username'])){
$output = webLoginAlert(WL_EMAILMISSMATCH).$tpl;
return;
}
// verify password
if ($_POST['password']!=$_POST['confirmpassword']) {
$output = webLoginAlert(WL_PASSMISSMATCH).$tpl;
return;
}
// check for duplicate user name
if($username=="") {
$output = webLoginAlert(WL_MISSINGUNAME).$tpl;
return;
}
else {
$sql = "SELECT id FROM ".$modx->getFullTableName("web_users")." WHERE username='$username'";
if(!$rs = $modx->db->query($sql)){
$output = webLoginAlert(WL_ERRONCKECHUNAME.$username).$tpl;
return;
}
$limit = $modx->db->getRecordCount($rs);
if($limit>0) {
$output = webLoginAlert(WL_UNAMEISUSED).$tpl;
return;
}
}
This changes the order of checking the db records, checking the email before the username.
Also it checks the the email against the username.
In register template, change field labeled as confirm email like this:
<tr>
<td>Confirm Email address:*</td>
<td>
<input type="text" name="username" class="inputBox" style="width:300px" size="20" value="[+username+]"></td>
</tr>
The reason for the difference is this snippet has been updated, which fixed ereg deprecation.