-
Notifications
You must be signed in to change notification settings - Fork 4
/
forget-password.php
142 lines (112 loc) · 5.52 KB
/
forget-password.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
ob_start();
$title = "Forgot password";
session_start();
include "init.php";
if (isset($_SESSION['username'])){
header('Location: profile.php?userID=' . $_SESSION["id"]);
exit;
}
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Load Composer's autoloader
require 'C:\xampp\composer\vendor\autoload.php';
// Instantiation and passing `true` enables exceptions
require 'C:\xampp\composer\vendor\phpmailer\phpmailer\src\Exception.php';
//require 'C:\xampp\composer\vendor\phpmailer\phpmailer\src\PHPMailer.php';
require 'C:\xampp\composer\vendor\phpmailer\phpmailer\src\SMTP.php';
// Import PHPMailer classes into the global namespace
$mail = new PHPMailer(true);
if($_SERVER["REQUEST_METHOD"]){
$valid = true;
if (isset($_POST['oublie'])){
$mail1 = filter_var($_POST['mail'],FILTER_SANITIZE_EMAIL); // On récupère le mail afin d envoyer le mail pour la récupèration du mot de passe
// Si le mail est vide alors on ne traite pas
if(empty(trim($mail1))){
$valid = false;
$er_mail = lang("EMAILERROR");
}
if($valid){
$stmt = $conn->prepare("SELECT * FROM users WHERE email = '$mail1'");
$stmt-> execute();
$result = $stmt->fetch();
if(!empty($result)){
$new_pass = generateRandomString();
$real_pass = sha1($new_pass);
$stmt1 = $conn->prepare("UPDATE users SET password = '$real_pass' WHERE email = '$mail1'");
$stmt1->execute();
//echo($verification_mail['mail']);
$succes_msg = lang("PASS-CHANGED") ;
if($stmt1){
try {
/* Set the mail sender. */
$mail->setFrom("addavigner@gmail.com");
/* Add a recipient. */
$mail->addAddress($mail1);
/* Set the subject. */
$mail->Subject = "New Password";
/* Set the mail message body. */
$mail->Body = "votre nouveau mot passe est : $new_pass . Vous pouvez changer se mot de passe dans les parametres";
/* Finally send the mail. */
$mail->send();
?>
<?php
header("location:login.php?success=" . $succes_msg);
exit();
}
catch (Exception $e)
{
/* PHPMailer exception. */
echo $e->errorMessage();
}
catch (\Exception $e)
{
/* PHP exception (note the backslash to select the global namespace Exception class). */
echo $e->getMessage();
}
}
else
echo "DATABASE ERROR";
}
else{
$fail_msg = lang("NO-EMAIL");
}
}
}
}
?>
<div class="w3-container w3-content w3-margin-top" style="min-height:-webkit-fill-available; ">
<div class="w3-main w3-white w3-card w3-padding">
<h3 class="w3-center w3-text-red"><?php echo lang("LOST-INFO") ?> !</h3>
<div class="w3-center alert alert-info">
<p><b><?php echo lang("FORGOT-PASS1") ?></b> </p>
<p> <?php echo lang("FORGOT-PASS2") ?> </p>
</div>
<br>
<form style="margin:0 20%" method="post" class="" action="">
<?php
if (isset($er_mail)){
?>
<div class="alert alert-danger"><?php echo $er_mail ?></div>
<?php
}
?>
<p class="input-container">
<input id="contEmail" class="w3-input w3-text-grey" type="email" placeholder="Email" name="mail" required value="<?php if (isset($_POST["mail"])) echo $_POST["mail"] ?>">
</p>
<div class="alert alert-danger w3-margin alert-contEmail"><?php echo lang('EMAILERROR') ?></div>
<p class="w3-center"><button type="submit" name="oublie" class="w3-teal w3-button w3-block"><?php echo lang("SEND") ?></button></p>
<?php if (isset($succes_msg)){ ?>
<p class="alert alert-success"><?php echo $succes_msg ?></p>
<?php } ?>
<?php if (isset($fail_msg)){ ?>
<p class="alert alert-danger"><?php echo $fail_msg ?></p>
<?php } ?>
</form>
</div>
</div>
<?php
include $tmp . 'footer.php';
ob_end_flush();
?>