-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforgotten-password.php
187 lines (172 loc) · 5.25 KB
/
forgotten-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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
include ('dbc.php');
if(isset($_SESSION["user_id"])){
header("location:account.php");
}
if(isset($_POST['send_email'])){
$query1 = "SELECT user_id FROM password_reset WHERE email = :email";
$statement1 = $dbc->prepare($query1);
$email =filter_input(INPUT_POST, 'email', FILTER_SANITIZE_STRING);
$vkey = md5(uniqid(rand()));
$statement1->execute(array(':email'=>$email));
$row = $statement1->fetch(PDO::FETCH_ASSOC);
if($statement1->rowCount()==1){
$id0 = $row['user_id'];
echo "You can only change password one time per day.";
}elseif($statement1->rowCount()==0){
$query3 = "SELECT user_id FROM users WHERE email=:email";
$statement3 = $dbc->prepare($query3);
$statement3->execute(array(":email"=>$email));
$row3 = $statement3->fetch(PDO::FETCH_ASSOC);
$id = $row3['user_id'];
if($statement3->rowCount()==1){
$query4 = "INSERT INTO password_reset (user_id, email, vkey) VALUES(:user_id, :email, :vkey)";
$statement4 = $dbc->prepare($query4);
if($statement4->execute(array(":user_id"=>$id, ":email"=>$email, ":vkey"=>$vkey))){
$to = $email;
$subject = 'Password Reset';
$from = '[email protected]';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Create email headers
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = '<html><head><style>
name{color:blue;}
#verify{color: brown;}
</style></head><body>';
$message .= 'Dear <name>'.get_user_name($id, $dbc).'</name>,';
$message .= '<br>To reset your password please click the link bellow:';
$message .= "<br><a href='https://special.social/resetpassword.php?userid=$id&vkey=$vkey'>Reset password here</a>";
$message .= '<br>Special Social';
$message .= '</body></html>';
if(mail($to,$subject,$message,$headers)){
echo "We have sent an email to $email. Please click on the password reset link in the email to generate a new password.";
}else{
echo "Sorry! Something went wrong.";
}
}
}else{
echo "Sorry! Wrong email address.";
}
}
}
?>
<html>
<head>
<title>Reset your forgotten password</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
</head>
<body>
<form method="POST">
<h3>Forgotten Password</h3>
<br><input type="email" name="email" placeholder="Email" required>
<button type="submit" name="send_email"> Send email </button>
<a onclick="history.back();">Back</a>
</form>
</body>
</html>
<style>
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@300&display=swap');
form {
overflow: hidden;
background-color: #2b3146;
margin: 10px;
border: 20px;
padding: 40px 30px 30px;
border-radius: 10px;
position: absolute;
top: 50%;
left: 50%;
width: 400px;
transform: translate(-50%, -50%);
box-shadow: 5px 10px 10px rgba(2, 128, 144, 0.2);
}
form > button {
cursor: pointer;
color: #fff;
font-size: 14px;
text-transform: uppercase;
border: 0;
padding: 10px 0;
margin-top: 10px;
margin-left: -12px;
border-radius: 5px;
background-color: #ff616f;
width: 100px;
}
form > button:hover {
background-color: #6fe0d1;
}
h3{
color: #6fe0d1;
position: absolute;
font-size: 30px;
left: 18%;
top: 0px;
}
body{
background-color: #6fe0d1;
font-family: 'Montserrat', sans-serif;
}
a{
color: #fff;
position: absolute;
font-size: 14px;
left: 85%;
bottom: 35%;
}
form > input {
display: block;
border-radius: 5px;
font-size: 16px;
background: white;
width: 104%;
border: 0;
padding: 10px 10px;
margin: 15px -10px;
}
@media only screen and (max-width: 500px){
form {
overflow: hidden;
background-color: #2b3146;
padding: 40px 30px 30px 30px;
margin: 10px;
border: 20px;
border-radius: 10px;
position: absolute;
top: 50%;
left: 50%;
width: 300px;
height: 125px;
transform: translate(-50%, -50%);
box-shadow: 5px 10px 10px rgba(2, 128, 144, 0.2);
}
form > input {
display: block;
border-radius: 5px;
font-size: 16px;
background: white;
width: 106%;
border: 0;
padding: 10px 10px;
margin: 15px -10px;
}
h3{
color: #6fe0d1;
position: absolute;
font-size: 30px;
left: 7%;
top: 0px;
}
a{
color: #fff;
position: absolute;
font-size: 14px;
left: 81%;
bottom: 33%;
}
}
</style>