<?php
require 'database.php';
include('smtp/PHPMailerAutoload.php');
$error="";

if(isset($_REQUEST['loginsubmit']))
{
$login_email = mysqli_real_escape_string($con, $_POST['login_email']);

if($login_email!='')
{
$loginpassword=md5($login_password);
$adminquery="select user_id from user_master where user_email='$login_email'";
$adminresult=mysqli_query($con,$adminquery);
$admindata  = mysqli_fetch_array($adminresult);
$user_id=$admindata['user_id'];
$count=mysqli_num_rows($adminresult);
if($count==1)
{
$password = random_int(10000, 99999);
$user_password = md5($password);
$updatesql ="UPDATE `user_master` SET `user_password`='$user_password' WHERE user_id='$user_id'";	
mysqli_query($con, $updatesql);	

$message  ='
<p>Dear <strong>'.$login_email.',</strong> </p>
<p>Your login details are as follows:</p>
<p><strong>Password: </strong> '.$password.' </p>
<p><br>Best Regards,,</p>
<p><strong>'.$user_name.'</strong></p>
<p><strong> SNA Associates </strong></p>
';

$subject ='Your Account Password';

$mail = new PHPMailer();
$mail->SMTPDebug  = false;
$mail->isSMTP();
$mail->SMTPAuth   = true;
$mail->Host       = "smtp.gmail.com";
$mail->Port       = 587; // TLS port
$mail->SMTPSecure = 'tls';
$mail->Username   = "notifications@snassociates.org.in";
$mail->Password   = "unjn wqld wlut cmzm"; // ❗ normal password नहीं चलेगा
$mail->isHTML(true);
$mail->CharSet = 'UTF-8';
$mail->setFrom("notifications@snassociates.org.in", "SNA Associates");
$mail->Subject = $subject;
$mail->Body    = $message;
$mail->addAddress($login_email);
// Optional
$mail->SMTPOptions = [
    'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => false
    ]
];

if(!$mail->send()){
    //echo "Mail Error: " . $mail->ErrorInfo;
}else{
    //echo "Mail Sent Successfully";
     $error="Your password has been sent to your registered email address. 
Please check your inbox and change your password after login.";
}
	
}
else
{
$error="Your Username is invalid";
}	
}
else
{
 $error="Please Enter Username and Password";	
}
	
}
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="keywords" content="">

    <link rel="icon" href="assets/img/favicon.png" type="image/x-icon">
    <link rel="shortcut icon" href="assets/img/favicon.png" type="image/x-icon">
    <title> SNA Associates </title>
    <!-- Google font-->
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&amp;display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&amp;display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Rubik:ital,wght@0,400;0,500;0,600;0,700;0,800;0,900;1,300;1,400;1,500;1,600;1,700;1,800;1,900&amp;display=swap" rel="stylesheet">
    <!-- Font Awesome-->
    <link rel="stylesheet" type="text/css" href="assets/css/fontawesome.css">
    <!-- ico-font-->
    <link rel="stylesheet" type="text/css" href="assets/css/icofont.css">
    <!-- Themify icon-->
    <link rel="stylesheet" type="text/css" href="assets/css/themify.css">
    <!-- Flag icon-->
    <link rel="stylesheet" type="text/css" href="assets/css/flag-icon.css">
    <!-- Feather icon-->
    <link rel="stylesheet" type="text/css" href="assets/css/feather-icon.css">
    <!-- Plugins css start-->
    <link rel="stylesheet" type="text/css" href="assets/css/sweetalert2.css">
    <!-- Plugins css Ends-->
    <!-- Bootstrap css-->
    <link rel="stylesheet" type="text/css" href="assets/css/bootstrap.css">
    <!-- App css-->
    <link rel="stylesheet" type="text/css" href="assets/css/style.css">
    <link id="color" rel="stylesheet" href="assets/css/color-1.css" media="screen">
    <!-- Responsive css-->
    <link rel="stylesheet" type="text/css" href="assets/css/responsive.css">
    


  </head>
  <body>
    <!-- Loader starts-->
    <div class="loader-wrapper">
      <div class="theme-loader">    
        <div class="loader-p"></div>
      </div>
    </div>
    <!-- Loader ends-->
    <!-- page-wrapper Start-->
    <section>         
      <div class="container-fluid p-0">
        <div class="row">
          <div class="col-12">              
            <div class="login-card">
              <form class="theme-form login-form" action="" method="post">
			    <center> <img src="assets/img/logo.png" style="width:220px"> </center>
                <h4>Forgot password</h4>
                <div class="form-group">
                  <label>Email Address</label>
                  <div class="input-group"><span class="input-group-text"><i class="icon-email"></i></span>
                    <input class="form-control" name="login_email" type="email" required="" placeholder="Test@gmail.com">
                  </div>
                </div>
             
                 
				<div class="form-group">
                  <div class="checkbox">
                    <input id="checkbox1" type="checkbox">
                   <!-- <label class="text-muted" for="checkbox1">Remember password</label> -->
                  </div><a class="link" href="login">Login?</a>
                </div>
				
                <div class="form-group">
                  <button class="btn btn-primary btn-block" type="submit" name="loginsubmit"> Submit </button>
                </div>
                
				<?php
				if($error)
				{
				?>
				<div class="m-t-2"><p class="text-danger"><?php echo $error; ?></p></div>
				<?php
				}
				?>
              </form>
            </div>
          </div>
        </div>
      </div>
    </section>
    <!-- page-wrapper end-->
	
	
    <!-- latest jquery-->
    <script src="assets/js/jquery-3.5.1.min.js"></script>
    <!-- feather icon js-->
    <script src="assets/js/icons/feather-icon/feather.min.js"></script>
    <script src="assets/js/icons/feather-icon/feather-icon.js"></script>
    <!-- Sidebar jquery-->
    <script src="assets/js/sidebar-menu.js"></script>
    <script src="assets/js/config.js"></script>
    <!-- Bootstrap js-->
    <script src="assets/js/bootstrap/popper.min.js"></script>
    <script src="assets/js/bootstrap/bootstrap.min.js"></script>
    <!-- Plugins JS start-->
    <script src="assets/js/sweet-alert/sweetalert.min.js"></script>
    <!-- Plugins JS Ends-->
    <!-- Theme js-->
    <script src="assets/js/script.js"></script>
    <!-- login js-->
    <!-- Plugin used-->
  </body>
</html>