-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforgotpassword.php
133 lines (112 loc) · 3.13 KB
/
forgotpassword.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
<?php
$error=null;
include 'database.php';
if($_SERVER["REQUEST_METHOD"]=="POST")
{
$user=$_POST['uname'];
$email=$_POST['email'];
try
{
//$result=mysql_query("SELECT * from users");
$result1=$db->prepare("SELECT * from users where username=?");
$result1->bindParam(1,$user);
$result1->execute();
$result2=$db->prepare("SELECT * from users where email=?");
$result2->bindParam(1,$email);
$result2->execute();
}
catch(exception $e)
{
$error= "OOPS! data cannot be fetched from Database";
}
$result1=$result1->fetch(PDO::FETCH_ASSOC);
$result2=$result2->fetch(PDO::FETCH_ASSOC);
if($result2 === FALSE)
{
$error= "Email not registered";
}
else if($result1 === FALSE)
{
$error= "No ".$user." found. Please Signup first";
}
else
{
try
{
//$result=mysql_query("SELECT * from users");
$result=$db->prepare("SELECT password from users where username=? and email=?");
$result->bindParam(1,$user);
$result->bindParam(2,$email);
$result->execute();
$result=$result->fetch(PDO::FETCH_ASSOC);
}
catch(exception $e)
{
$error= "OOPS! data cannot be fetched from Database";
}
if($result === FALSE)
{
$error= "OOPS! Something went wrong.";
}
else
{
$mailbody=$result['password'];
include("phpmailer/class.smtp.php");
require_once 'phpmailer/PHPMailerAutoload.php';
$mail=new PHPMailer;
$mail->IsSmtp();
$mail->SMTPDebug=1;
$mail->SMTPAuth=true;
$mail->SMTPSecure='ssl';
$mail->Host="ssl://smtp.gmail.com";
$mail->Port=465;
$mail->IsHTML(true);
$mail->Username="[email protected]";
$mail->Password="sonyxperia1";
$mail->SetFrom($email);
$mail->Subject="Password";
$mail->Body=$mailbody;
$mail->AddAddress($email);
if($mail->Send())
{
?>
<script>
location.replace("login.php");
</script><?php
}
else
{
$errormessage= "OOPs!!!!! SomeThing went wrong. Please after some time.";
}
}// TODO: better error handling
}
}
?>
<?php
$header = "Forgot Password";
include('header.php');
?>
<html>
<?php $message="Enter your Username and Email "?>
<div class="imgcontainer">
<img src="login.png" alt="Avatar" class="avatar">
</div>
<p class="text-center"><?php
if($error == null) echo $message;
else{ ?><h4 class="error text-center"><?php echo $error;}?>
</h4></p>
<form action="" method="post">
<div class="container">
<label for="uname"><b>Username</b></label>
<input type="text" name="uname" required>
<label for="email"><b>Email</b></label>
<input type="text" name="email" required>
<button type="submit">Sign Up</button>
</div>
<div class="container" style="background-color:#f1f1f1">
<span class=""><a href="signup.php">Sign Up</a></span>
<span class="psw"><a href="login.php">Login</a></span>
</div>
</form>
</html>
<?php include('footer.php');?>