forget-password_sq.php
PHP:
<?php
session_start();
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Send Reset Password Link with Expiry Time in PHP MySQL</title>
<!-- CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
<link rel="stylesheet" href="css/fpws.css">
</head>
<style>
body{
background-image: url('images/bglogin.jpg');
background-image: no-repeat;
background-size: cover;
}
</style>
<body>
<div class="container">
<div class="card">
<div class="card-header text-center">
<h1>Forgot Password</h1>
Enter your email address
</div>
<span class="success" align="center" style="background:lightgreen">
<?php
if(isset($_SESSION['email']))
{
echo $_SESSION['email'];
unset($_SESSION['email']);
}
?>
</span>
<span align="center" style="background-color: #FFD2D2; color:white;" class="error">
<?php
if(isset($_SESSION['error']))
{
echo $_SESSION['error'];
unset($_SESSION['error']);
}
?>
</span>
<div class="card-body">
<form action="password-reset-tokensqa.php" method="post">
<div class="form-group">
<input type="email" name="email" class="form-control" id="email" placeholder=" ex. juan@gmail.com" aria-describedby="emailHelp"required>
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<div class="form-group">
<label for="question"><b>Security Question </b></label>
<select id="" name="question" class="form-control select1 " required >
<option value="<?php echo isset($meta['question']) ? $meta['question']: '' ?>"><?php echo isset($meta['question']) ? $meta['question']: '' ?></option>
<option value="What is your date of birth?">What is your date of birth? </option>
<option value="What was your favorite school teacher’s name?">What was your favorite school teacher’s name? </option>
<option value="What’s your favorite movie?">What’s your favorite movie? </option>
<option value="What was your first car?">What was your first car? </option>
<option value="What city were you born in?">What city were you born in? </option>
</select>
</div>
<div class="form-group">
<label for="password"><b>Answer</b> </label>
<input type="text" name="ans" id="" class="form-control" value="<?php echo isset($meta['ans']) ? $meta['ans']: '' ?>" required>
</div>
<input type="submit" name="password-reset-tokensqa" class="btn btn-primary">
<br><br>
<span class="lg">
Already have an account? <br> <a href="logins.php"> <small>Login here </small> </a> | <a href="forget-password.php"> <small>Reset PW Email</small> </a>
</span>
</form>
</div>
</div>
</div>
</body>
</html>
password-reset-tokensqa.php
PHP:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
session_start();
if(isset($_POST['password-reset-tokensqa']) && $_POST['email'])
{
include 'db_connect.php';
$email = $_POST['email'];
$password = 'password';
$result = mysqli_query($conn,"SELECT * FROM users WHERE email='" . $email . "'");
$row= mysqli_fetch_array($result);
if($row)
{
$token = md5($email).rand(10,9999);
$expFormat = mktime(
date("H"), date("i"), date("s"), date("m") ,date("d")+1, date("Y")
);
$expDate = date("Y-m-d H:i:s",$expFormat);
$update = mysqli_query($conn,"UPDATE users set password ='" . md5($password) . "', reset_link_token='" . $token . "' ,exp_date='" . $expDate . "' WHERE email='" . $email . "'");
$link = "<a href='cms/reset-password.php?key=".$email."&token=".$token."'>Click to Reset password</a>";
require_once('fpwvendor/autoload.php');
$mail = new PHPMailer(true);
$mail->CharSet = "utf-8";
$mail->IsSMTP();
// enable SMTP authentication
$mail->SMTPAuth = true;
// GMAIL username
$mail->Username = "qq@gmail.com";
// GMAIL password
$mail->Password = "qq";
$mail->SMTPSecure = "ssl";
// sets GMAIL as the SMTP server
$mail->Host = "smtp.gmail.com";
// set the SMTP port for the GMAIL server
$mail->Port = "465";
$mail->From='qq@gmail.com';
$mail->FromName='xx : Courier ';
$mail->AddAddress($email);
$mail->Subject = 'Reset Password';
$mail->IsHTML(true);
$mail->Body = 'Click on this Link to Reset Password '.$link.'';
if($mail->Send())
{
$_SESSION['email']="We've sent you a reset password in your gmail account - ".$email."" ;
header( "refresh:1;url=forget-password_sq.php" );
}
else
{
echo "Mail Error - >".$mail->ErrorInfo;
}
}else{
$_SESSION['error']="Invalid Email Address Please check carefully ".$email."";
header( "refresh:1;url=forget-password_sq.php" );
}
}
?>
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.