Forgot MC User Name
- Register Group with Captcha
- View Group Profile
- Edit Group Profile
- MC (Microcommunity) Search and Match
- MC (Microcommunity) Search and Match — Security
- MC (Microcommunity) Search and Match — JavaScript
- MC (Microcommunity) Search and Match — Form
- MC (Microcommunity) Search and Match — PHP
- MC Questionnaire
- Microcommunity (MC) Registration Script — Enter Questionnaire Data in Database
- MC Search and Match Profile and Account Management
- Login to MC Search and Match Profile and Account Management
- Logout of MC Search and Match Profile and Account Management
- MC Questionnaire Login
- MC Questionnaire Info
- Delete Group Account
- Forgot User Name
- Forgot Password
- Form to Send Private Message
- Send Private Message
- Private Message Outbox
- Private Message Inbox
- Delete Private Message from Inbox
- Delete Private Message from Outbox
- Private Message Logout
- Private Message Session Monitoring
- MC (Microcommunity) Search and Match Session Monitoring
- Configure File for Database Connection
- Captcha Script for Registration and Login
This script is called forgot-user-name.php
The first section is at the start of the script. First, we define a named constant '_NODIRECTACCESS'. We include the config.php file (in the includes folder) which uses the PHP defined() function to check on this constant. If it is not set, we are thrown out of the config.php file like yesterday's trash.
We get the POSTed email address and stick it in the PHP variable $email. Then we make sure it is not too long or too short. If it is, we give them an alert and send them off to the registration script Register Group with Captcha. Then we run a standard email validation script and if their email fails, we give them an alert and send them off to the registration script. This validator uses the preg_match function, which performs a regular expression match on $email. We use the mysql_real_escape_string() function to make their input safe to use in a MySQL statement that searches for $email, since it escapes special characters in the string for use in our SELECT . . . WHERE SQL statement.
We use the mysql_num_rows() function to determine whether or not the email address we search for in the MySQL database table was found, and, if not, we give the user an alert "This email address does not exist. Please try again." If it is found, we use the mysql_fetch_array() function to get the results in an array and we grab the contents of the username and email fields from this array. We use these in an email. In order to send the user his user name, we use an email since it is safer than looking it up for them on the spot. The visitor may indeed know someone's email address, but that does not prove it's HIS email. We dispel doubts by sending the user the info knowing that only the true owner of that email address will get the info.
It is obvious where the $email and $U variables get their data, but not so obvious where $psbhostemailaddress comes from. It is defined in the config.php file: Configure File for Database Connection. It is used as the From in the email's headers data.
The form is standard stuff, and it contains a link to the page Login to MC Search and Match Profile and Account Management. The form uses an onsubmit event to run the JavaScript function validateemail(), which validates the email, or refuses to submit the form, if the email won't validate.
The script below is called: forgot-user-name.php
<?php
define('_NODIRECTACCESS', TRUE);
include_once"includes/config.php";
$email=$_POST['email'];
if(isset($email)){
if (strlen($email)<6 || strlen($email)>65) {echo '<script language="javascript">alert("Please enter 6 to 65 characters for email address."); window.location = "register-with-captcha.php"; </script>';
}else{
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) {
echo '<script language="javascript">alert("That email address is not valid."); window.location = "register-with-captcha.php"; </script>';
}else{
$email=mysql_real_escape_string($email);
if($email<>""){
$check_user_data = mysql_query("SELECT * FROM mc_members WHERE email = '$email'") or die(mysql_error());
if(mysql_num_rows($check_user_data) == 0)
{echo '<script language="javascript">alert("This email address does not exist. Please try again.")</script>;';unset($email);}
else {$row = mysql_fetch_array($check_user_data);$E=$row['email'];$U=$row['username'];
echo "<script language='javascript'>alert('Your user name is ".$U."');</script>";
$to = $email;
$subject = "Here are your login details . . . ";
$message = "This is in response to your request for login details as administrator of your MC group.\n\nYour User Name is ".$U.".\n\nYour password is the same one you were already using.\n\nDon't give your password to anyone in your group, but do save it somewhere safe.\n\nRegards,\n\nthe management";
$headers = "From: ".$psbhostemailaddress."\r\nReply-To: ".$email;
if(mail($to, $subject, $message, $headers)){echo "<center><font face='Verdana' size='2'><b><br><br><br><br><br>THANK YOU</b> <br>Your user name was posted to your email address. Please check your mail soon.</center>";}
else{echo "<center><font face='Verdana' size='2' color=red>There is some system problem in sending login details to your address. <br><br><input type='button' value='Retry' onClick='history.go(-1)'></center></font>";}
}}}}}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<TITLE>User Name Recovery—Forgotten User Name</TITLE>
<meta name="description" content="User Name Recovery—Forgotten User Name">
<meta name="keywords" content="User Name Recovery,Forgotten User Name,forgot username,forgotten username,forgot user name,forgotten user name,recover forgotten user name,php,javascript, dhtml, DHTML">
<style type="text/css">
BODY {margin-left:0; margin-right:0; margin-top:0;text-align:left;background-color:#bbb}
p, li {font:13px Verdana; color:black;text-align:left}
h1 {font:bold 28px Verdana; color:black;text-align:center}
h2 {font:bold 24px Verdana;text-align:center}
h3 {font:bold 15px Verdana;}
.main {position:absolute;width:700px;top:150px;left:150px;padding:30px;text-align:left;border:8px groove blue;background-color:#ddd}
</style>
<div class='main'>
<p><center><B><h2>User Name Recovery—Forgotten User Name</h2></B></center></p>
<form name="MyForm" method="POST" onsubmit="return validateemail()" action="forgot-user-name.php">
<label for='email'><b>Email address: </b><input type="text" name="email" value="" size="30" maxlength='60'></label><br><br>
<center><input type="submit" value="Recover Forgotten User Name"><br><br></center>
<center><input type="reset" value="Reset"><br><br></center>
<center><input type="button" value="Login" onClick="window.location='login-to-mc.php'"><br><br></center><br><br></center>
</form>
</div>
<script language="javascript">
function validateemail(){
var ck_email = /^[A-Za-z0-9-_]+(\.[A-Za-z0-9-_]+)*@([A-Za-z0-9-_]+\.)?([A-Za-z0-9-_]+(\.[A-Za-z]{2,6})(\.[A-Za-z]{2})?)$/;
if (document.MyForm.email.value.search(ck_email)==-1)
{alert("That email address is not valid.");return false}
return true}
</script>
</body></html>