CREATE TABLE IF NOT EXISTS `employee` (
`EMPLOYEE_ID` int(25) NOT NULL,
`FIRST_NAME` varchar(255) NOT NULL,
`LAST_NAME` varchar(255) NOT NULL,
`EMPLOYEE_EMAIL` varchar(255) NOT NULL,
`PASSWORD` varchar(50) DEFAULT NULL,
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `TOKEN` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`EMPLOYEE_EMAIL` varchar(100) NOT NULL,
`TOKEN` varchar(100) NOT NULL,
`STATUS` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;
Step1:
Create Form:
<form method="post" name="forgot" id="forgot">
<!-- Modal -->
<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="forgotPass" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Forgot Password ?</h4>
</div>
<div class="modal-body">
<p>Enter your e-mail address below to reset your password.</p>
<input type="text" name="email2" id="email2" placeholder="Email" autocomplete="off" class="form-control placeholder-no-fix">
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default" type="button">Cancel</button>
<input type="submit" value="Send" name="send" class="btn btn-success">
<!-- <button class="btn btn-success" type="button">Submit</button>-->
</div>
</div>
</div>
</div>
<!-- modal -->
</form>
Step2:
Checking Entered Email is Existed or not and Sent Reset password mail if mail is already Existed
<?php
$conn=mysql_connect("hostname","username","password")
mysql_select_db("databasename",$conn);
if(isset($_POST['send'])) {
$email=$_POST['email2'];
$sql="SELECT EMPLOYEE_ID,EMPLOYEE_EMAIL,PASSWORD from EMPLOYEE where EMPLOYEE_EMAIL='".$email."'";
$q=mysql_query($sql);
$p=mysql_affected_rows();
if($p!=0)
{
$res=mysql_fetch_array($q);
$to=$res['EMPLOYEE_EMAIL'];
$token=rand();
$q="insert into TOKEN (TOKEN,EMPLOYEE_EMAIL) values ('".$token."','".$email."')";
mysql_query($q);
$subject=' password Recovery';
$from = 'FAD@imcrinox.com'; // give from email address
// mandatory headers for email message, change if you need something different in your setting.
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $from . "\r\n";
$headers .= "CC: arundsti@gmail.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<span style="color:Green;font-size:20px;"> PASSWORD RECOVERY</span> ';
$message .= '<table rules="all" border=1 style="border-color: green;" cellpadding="10" align="center">';
$message .= "<tr style='background: #eee;'><td><strong>Email:</strong> </td><td>" . strip_tags($res['EMPLOYEE_EMAIL']) . "</td></tr>";
$message .= "<tr><td><strong>PASSWORD:</strong> </td><td>" . "<a href='http://website.com/foldername/subfoldername/reset.php?token=$token'>ResetPassword</a>" . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
$m=mail($to,$subject,$message,$headers);
if($m)
{
$msg='Check your mail inbox for Reset password ';
}
else
{
$msg='Email not found please signup now!!';
}
}
else
{
$msg='Invalid Email';
}
}
?>
Step3:Checking mail
reset.php
<?php session_start();
$token=$_GET['token'];
if(!isset($_POST['password'])){
$q="select EMPLOYEE_EMAIL from TOKEN where TOKEN='".$token."' and STATUS=0";
$r=mysql_query($q);
while($row=mysql_fetch_array($r))
{
$email=$row['EMPLOYEE_EMAIL'];
}
If ($email!=''){
$_SESSION['EMPLOYEE_EMAIL']=$email;
}
else die("Invalid link or Password already changed<a href='index.php'>Login here</a>");}
$pass=$_POST['password'];
$email=$_SESSION['EMPLOYEE_EMAIL'];
if(!isset($pass)){
echo '<form method="post">
enter your new password:<input type="password" name="password" />
<input type="submit" value="Change Password">
</form>
';}
if(isset($_POST['password']))
{
$q="update EMPLOYEE set PASSWORD='".$pass."' where EMPLOYEE_EMAIL='".$email."'";
$r=mysql_query($q);
if($r)mysql_query("update TOKEN set STATUS=1 where TOKEN='".$token."'");
echo "Your password is changed successfully<a href='index.php'>Login Here</a>";
if(!$r)echo "An error occurred";
}
?>
03:17
Share:
0 comments: