-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathotp.php
More file actions
141 lines (118 loc) · 4.79 KB
/
Copy pathotp.php
File metadata and controls
141 lines (118 loc) · 4.79 KB
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
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Fonts -->
<link rel="dns-prefetch" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css?family=Raleway:300,400,600" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="style.css">
<link rel="icon" href="Favicon.png">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<title>Login Form</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light navbar-laravel">
<div class="container">
<a class="navbar-brand" href="#">User Password Recover</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</nav>
<main class="login-form">
<div class="cotainer">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Password Recover</div>
<div class="card-body">
<form action="#" method="POST" name="recover_psw">
<div class="form-group row">
<label for="email_address" class="col-md-4 col-form-label text-md-right">E-Mail Address</label>
<div class="col-md-6">
<input type="text" id="email_address" class="form-control" name="email" required autofocus>
</div>
</div>
<div class="col-md-6 offset-md-4">
<input type="submit" value="Recover" name="recover">
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</main>
</body>
</html>
<?php
if(isset($_POST["recover"])){
include('dbconn.php');
$email = $_POST["email"];
$sql = mysqli_query($conn, "SELECT * FROM user WHERE email='$email'");
$query = mysqli_num_rows($sql);
$fetch = mysqli_fetch_assoc($sql);
if(mysqli_num_rows($sql) <= 0){
?>
<script>
alert("<?php echo "Sorry, no emails exists "?>");
</script>
<?php
}else if($fetch["status"] == 0){
?>
<script>
alert("Sorry, your account must verify first, before you recover your password !");
window.location.replace("index.php");
</script>
<?php
}else{
// generate token by binaryhexa
$token = bin2hex(random_bytes(50));
//session_start ();
$_SESSION['token'] = $token;
$_SESSION['email'] = $email;
require "Mail/phpmailer/PHPMailerAutoload.php";
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host='smtp.gmail.com';
$mail->Port=587;
$mail->SMTPAuth=true;
$mail->SMTPSecure='tls';
// h-hotel account
$mail->Username='projectwork42058@gmail.com';
$mail->Password='project42058';
// send by h-hotel email
$mail->setFrom('projectwork42058@gmail.com', 'Password Reset');
// get email from input
$mail->addAddress($_POST["email"]);
//$mail->addReplyTo('lamkaizhe16@gmail.com');
// HTML body
$mail->isHTML(true);
$mail->Subject="Recover your password";
$mail->Body="<b>Dear User</b>
<h3>We received a request to reset your password.</h3>
<p>Kindly click the below link to reset your password</p>
http://localhost/login-System/Login-System-main/changepass_psw.php
<br><br>
<p>With regrads,</p>
<b>Programming with Lam</b>";
if(!$mail->send()){
?>
<script>
alert("<?php echo " Invalid Email "?>");
</script>
<?php
}else{
?>
<script>
window.location.replace("notification.html");
</script>
<?php
}
}
}
?>