forked from Bkoech/gbvis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpassword_request.php
executable file
·119 lines (96 loc) · 4.13 KB
/
password_request.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
<?php
//login.php
$page_title = "Password request| GBV";
$current_page = "Login";
require_once 'includes/global.inc.php';
include "Data_uploadandapproval/smtpmail/classes/class.phpmailer.php"; // include the class name
$msg = "";
$username = "";
$email = "";
//check to see if they've submitted the login form
if(isset($_POST['password_request'])) {
$username = $_POST['username'];
$email = $_POST['email2'];
if($username == "" || $email == ""){
$msg = "<div class='alert alert-warning'>
<button class='close' data-dismiss='alert'>×</button>
Please provide username and email.
</div>";
}else{
$userTools = new UserTools();
$token = uniqid($email);
if($userTools->checkUsernameExists($username) && $userTools->checkEmailExists($email) && $userTools->set_reset_password_token($email, $username, $token)){
//successful redirect them to a page
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "norbertglen7@gmail.com";
$mail->Password = "ldirdkmehmfdatgw";
$mail->SetFrom("sgbvis@ngeckenya.org");
$mail->Subject = "KenyaSGBVIS Account Password Recovery";
$mail->Body = "<b>Hi, You recently requested to change your KenyaSGBVIS account password. Please follow the following link to reset password. <br/><br/> <a href='http://localhost/gbvis/password_change.php?token=".$token."'>Click here</a></b>";
$mail->AddAddress($email);
if(!$mail->Send()){
$msg = "<div class='alert alert-warning'>
<button class='close' data-dismiss='alert'>×</button>
".$mail->ErrorInfo."
</div>";
}
else{
$msg = "<div class='alert alert-success'>
<button class='close right' data-dismiss='alert'>×</button><br>
We've sent an email to $email.
Please click on the password reset link in the email to generate new password.
</div>";
}
//header("Location: index.php");
}else{
// header("Location: index.php");
$to = $email;
$subject = "Password Recovery Attempt";
$txt = "There has been a password recovery attempt by".$email;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "X-Mailer: PHP/" . phpversion() . "\r\n";
$headers .= "From: <norbertglen7@yahoo.com>";
mail($to,$subject,$txt,$headers);
$msg = "<div class='alert alert-warning'>
<button class='close right' data-dismiss='alert'>×</button>
Incorrect username and email. Please try again.
</div>";
}
}
}
include "includes/Dash_header.php"; //TA:60:1
?>
<!-- Code Begins -->
<center>
<div class="login_wrapper">
<br clear="all">
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div class="message"><?php echo $msg; ?></div>
<h4 style="margin-top:0px;">Please provide us with following information</h4><br />
<div class="labelsDiv">Username:</div>
<div class="inputsDiv"><input type="text" name="username" id="username" value="" class="textInputs"></div><br clear="all"><br clear="all">
<div class="labelsDiv">Email:</div>
<div class="inputsDiv"><input type="text" name="email2" id="email2" value="" class="textInputs"></div><br clear="all"><br clear="all">
<div class="labelsDiv"> </div>
<div class="inputsDiv">
<input type="submit" name="password_request" id="" value="Submit" style="margin-right:50px; width:38%" class="login_button">
<input type="reset" name="reset" id="" value="Reset" style="width:38%" class="login_button">
</div>
</form>
<br clear="all"><br clear="all">
</div>
</center>
<!-- Code Ends -->
<!-- TA:60:1 -->
<?php include "includes/footer.php";?>
</center>
</body>
</html>