-
Notifications
You must be signed in to change notification settings - Fork 1
/
forgotpassword.php
130 lines (121 loc) · 4.84 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
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
<head>
<title>Forgot password</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.1/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.1/js/materialize.min.js"></script>
<style>
.iris {
background-image: url('images/new.jpg');
background-repeat: no-repeat;
height: 150vh;
background-size: cover;
}
</style>
</head>
<body>
<?php
session_start();
// put your code here
if(isset($_GET['email']))
{
$email=$_GET['email'];
try
{
$dbhandler = new PDO('mysql:host=localhost;dbname=dm_project','root','');
//echo "Connection is established...<br/>";
$dbhandler->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$query=$dbhandler->prepare("select * from users where email=?");
$query->execute(array($email));
$count = $query->rowcount();
if($count!=0)
{
$_SESSION['email']=$email;
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host="smtp.gmail.com";
$mail->Port=587;
$mail->SMTPAuth=true;
$mail->SMTPSecure='tls';
$mail->Username='[email protected]';
$mail->Password='ayan123456';
$mail->setFrom('[email protected]');
$mail->addAddress($email);
$mail->addReplyTo('[email protected]');
$mail->isHTML();
$mail->Subject="Resetting password";
function randomNumber($length)
{
$result = '';
for($i = 0; $i < $length; $i++)
{
$result .= mt_rand(0, 9);
}
return $result;
}
$code= randomNumber(4);
$_SESSION['code']=$code;
$mail->Body="Hello,<br><h2>your verificaton code is $code</h2>. Use this code to reset your password";
if(!$mail->send())
{
echo "fail";
}
else
{
$_SESSION['flag']='1';
header('location:resetpassword.php');
}
}
else
{
session_start();
session_destroy();
header("location:forgotpassword.php?msg=Invalid Email");
}
}
catch(PDOException $e)
{
echo $e->getMessage();
die();
}
}
?>
<br>
<div class="teal lighten-2 center"><a href="home.php" class="teal lighten-2" style="font-size: 40px;color: #000;"><b>Forgot Password</b></a></div>
<?php
if(isset($_GET['msg']))
{
?>
<div style="font-size:25px;" class="teal lighten-2 center"> <?php echo $_GET['msg'] ?> </div>
<?php
}
?>
<br><br>
<form action="forgotpassword.php" class="container login-form" style="padding-left: 10%;padding-right: 10%;">
<div class="row">
<div class="input-field col s12">
<i class="mdi-social-person-outline prefix"></i>
<input class="validate" id="username" name="email" type="text" placeholder="Email-id" required>
<label for="text" data-error="wrong" data-success="right" class="center-align"></label>
</div>
</div>
<div class="row">
<div class="center input-field col s12">
<input style="width: 52em;" class="center btn teal lighten-2" type="submit" value="Send Code">
</div>
</div>
</form>
<div class="row container" style="padding-left: 10%;padding-right: 10%;">
<div class="input-field col s4 m4 l4">
<a class="margin medium-small btn green" href="login.php">Back to login page</a>
</div>
</div>
</body>
</html>