File "forgot_password.php"

Full Path: /home/analogde/www/Design/fileman/Fusion/PROD/forgot_password.php
File size: 7.12 KB
MIME-type: text/x-php
Charset: utf-8

<?php
/*
// https://github.com/suresh-pokharel/forgot-password/blob/master/forgot_password.php

	// value="<?php echo isset($_POST['email']) ? $_POST['email'] : ''; ?>"
*/
   
/*	
	CREATE TABLE appli_table_forget_password (
  id int(11) NOT NULL AUTO_INCREMENT,
  email varchar(200) NOT NULL,
  temp_key varchar(200) NOT NULL,
  created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

	*/
	
	require_once("config_DB.php");

	$valide = "";
	
	if($_SERVER["REQUEST_METHOD"] == "POST")
	{
		echo "Bingo...";

		$valide = "ok";
    
		$email_reg = mysqli_real_escape_string( $connexion ,$_POST['email'] );
		 
		$message_success=" Please check your email inbox or spam folder and follow the steps";
        
		//generating the random key
		$key=md5(time()+123456789% rand(4000, 55000000));

		//insert this temporary key into database
		$sql_insert=mysqli_query( $connexion ,"INSERT INTO appli_table_forget_password(email,temp_key) VALUES('$email_reg','$key')");

		//sending email about update
		$to      = $email_reg;
		$subject = 'Changing password';

//		$verificationLink = "https://analog-design.net/Fusion/login_register/Nouveau%20dossier/validation_compte_send_email.php?code=$verificationCode";


//		$msg = "Please copy the link and paste in your browser address bar". "\r\n"."www.psuresh.com.np/misc/forgot-password-php/forgot_password_reset.php?key=".$key."&email=".$email_reg;
		
		$msg = "Please copy the link and paste in your browser address bar". "\r\n"."https://analog-design.net/Fusion/PROD/forgot_password_reset.php?key=".$key."&email=".$email_reg;
		
		$headers = 'From: Administration du gestionnaire de contenu' . "\r\n";
		mail($to, $subject, $msg, $headers);
	}
	
?>

<!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>blabla</title>

<link rel="icon" type="image/x-icon" href="/images/favicon.ico"> 

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

<link rel="stylesheet"  href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.3.0/font/bootstrap-icons.css" />

<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>

<style>
.error{
	display: none;
	margin-left: 10px;
}		

.text-danger{
	display: none;
	margin-left: 10px;
}	

.error_show{
	color: red;
	margin-left: 10px;
}

.help-block { display: none; }

.form-group.has-error .help-block { display: block; }

</style>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>

function check() 
{
	//var validRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;

/*	
	function validateEmail($email) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    return reg.test($email);
}
*/	
	if ($("#email").val().match( /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ 	 )) 
	{
		$('.erreur_email').hide();
		$('.erreur_email').text("Check : Le format standard de l'adresse email est valide ");
		$(".erreur_email").css("color","GREEN");
		$('.erreur_email').show();
	}
	else
	{
		$('.erreur_email').hide();
		$('.erreur_email').text("Check : Le format standard de l'adresse email n'est pas valide !");
		$(".erreur_email").css("color","RED");
		$('.erreur_email').show();
	}
		
	
	jQuery.ajax({
	url: "verification_email.php",
	data:'email='+$("#email").val(),
	type: "POST",
	success:function(data)
	{
		$("#email-status").html(data);
		
		
		
		const str =  data; 
		const substr = 'existe';
	
		if( str.indexOf(substr) > 0 )
		{
			// Enable 
			$( "#submit" ).prop( "disabled", false );
		}
		else
		{
			$( "#submit" ).prop( "disabled", true );
		}
		
	},
	error:function (){}
	});
	
}

</script>

<style>

.login-form {
    width: 500px;
    margin: 50px auto;
}
.login-form form {        
    margin-bottom: 15px;
    background: #f7f7f7;
    box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
    padding: 30px;
}
.login-form h2 {
    margin: 0 0 15px;
}
.form-control, .btn {
    min-height: 38px;
    border-radius: 2px;
}
.input-group-addon .fa {
    font-size: 18px;
}
.btn {        
    font-size: 15px;
    font-weight: bold;
}
.bottom-action {
  	font-size: 14px;
}

.erreur_utilisateur { display: none;
                       color: red; }

.erreur_password { display: none;
                       color: red; }
    

</style>
</head>
<body>
<div class="login-form">
    <form id="login_form" action="" method="post">
        <!--
		<h2 class="text-center">Récupération</h2>  
		-->	
		<!--
		
		<i class='fas fa-bug' style='font-size:36px'></i>
		-->
        <header class="login--header login-1--header text-center">
				<span class="icon icon-medium fa fa-bug"  style='font-size:48px'  ></span>
				<h3>Connexion</h3>
				<span class="arrow-down login--header__arrow"></span>
		</header>
				
		<div class="form-group">
            <label for="email" class="form-label">Veuillez saisir votre email pour réinitialser votre mot de passe</label>
			<br><br>
			<!--
			<label>Veuillez saisir votre email pour réinitialser votre mot de passe
			Please enter your email to recover your password</label><br><br>
			-->
			<div class="input-group">
			
                <div class="input-group-prepend">
                    <span class="input-group-text">
                        <i class="fa fa fa-envelope"></i>
                    </span>                    
                </div>
				
                <input type="text" class="form-control" id = "email" name = "email" onInput="check()" placeholder="Saisir votre email" autocomplete="nada" >
				<p class="erreur_email"></p>
				<span id="email-status"></span>
            </div>
        </div>  
		
        <div class="form-group">
			 <input type="submit" id = "submit" name = "submit" value="Valider" disabled class="btn btn-primary btn-block" />
		<!--
            <button type="submit" name="submit"  disabled class="btn btn-primary btn-block">Valider</button>
        -->
		</div>
		
		<?php
		if($valide == "ok")
		{
		?>
		<div class="alert alert-success" role="alert">
		Un email vient d'être envoyée pour réinitiasiser votre mot de passe.
		</div>
		<?php
		}
		?>
        <!--
		<div class="bottom-action clearfix">
            <a href="#" class="float-center">Mot de passe oublié ?</a>
        </div>  
		-->
		
    </form>
    <p class="text-center small"><a href="javascript:history.go(-1)">Retour ...</a>.</p>
	<!--
	echo "<a href=\"javascript:history.go(-1)\">GO BACK</a>";
	-->
<br>
<br>


</div>
</body>
</html>