-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlostPassword.php
More file actions
156 lines (130 loc) · 5.58 KB
/
lostPassword.php
File metadata and controls
156 lines (130 loc) · 5.58 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
require_once('config.php');
require(__DIR__.'\PHPMailer-5.2-stable\PHPMailerAutoload.php');
ob_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST' $$ isset($_POST['xsrf'])) {
if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$tabLost["error_msg"] = "Email format is invalid. Is it correct?";
$tabLost["title"] = "Wait a minute...";
$tabLost["icon"] = "error";
$tabLost["btn_text"] = "Oh..";
echo json_encode($tab_Lost);
die();
}
if($_POST['xsrf'] !== $_SESSION['xsrf']){
echo "xsrf error";
unset($_SESSION['xsrf']);
die();
}
unset($_SESSION['xsrf']);
$email = $link->real_escape_string($_POST['email']);
$tabLost = ["error_msg"=>"Message with link has been sent to your email!", "title"=>"Done!", "icon"=>"success", "btn_text"=>"Uff!"];
$check = $link->query("SELECT email FROM users WHERE email='$email'");
$checkNum = $check->num_rows;
if ($checkNum != 1){
$tabLost["error_msg"] = "There is no registred email like that. Is it correct?";
$tabLost["title"] = "Wait a minute...";
$tabLost["icon"] = "error";
$tabLost["btn_text"] = "Oh..";
} else {
$hash = md5(rand(0,1000));
$check = $link->query("UPDATE users SET hash='$hash' WHERE email='$email'");
$email_message =
'Hi! We heard that you lost your password. To change it, click this link".
http://yourpage.com/passRenew?hash='.$hash.'<br>
You did not ask for password change? Contact admin right now.' ;
$email_message = wordwrap($email_message, 70, "\r\n");
$mail = new PHPMailer();
$mail->CharSet = "UTF-8";
$mail->IsSMTP();
$mail->Host = $serwer_smtp;
$mail->Port = $port_smtp;
$mail->SMTPAuth = true;
$mail->Username = $smtplog;
$mail->Password = $smtppass;
$mail->From = 'from who?';
$mail->SMTPSecure = 'ssl';
$mail->FromName = 'your name';
$mail->AddAddress($email);
$mail->WordWrap = 50;
$mail->Priority = 1;
$mail->Subject = 'Password renew';
$mail->Body='<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>LOST PASSWORD</title>
<style type="text/css">
body {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
overflow: hidden;
}
main {
height: 100vh;
width: 100%;
}
header {
background-color: rgb(84, 150, 255);
height: 10vh;
text-align: center;
font-size: 7vh;
font-family: "Arial";
line-height: 10vh;
color: white;
margin-top: 10vh;
margin-right: 20%;
margin-left: 20%;
margin-bottom: 10vh;
}
.textt {
font-size: 20px;
font-size: 3vh;
text-align: center;
font-family: "verdana";
margin-right: 20%;
margin-left: 20%;
margin-bottom: 10vh;
}
.c {
font-size: 3vh;
margin-right: 1vh;
color: black;
position: absolute;
right: 50vh;
font-family: "verdana";
}
</head>
<body>
<main>
<header>
PASSWORD RENEW
</header>
<div class="textt">
'.$email_message.'
</div>
<div class="c">
Your company name
</div>
</main>
</body>
</html>';
$mail->isHTML(true);
$mail->AltBody = $email_message;
if(!$mail->send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
$tab_Lost["error_msg"]= "Mail nie został wysłany, skontaktuj się z administracją, aby ręcznie zmienić hasło.";
$tab_Lost["title"]="Błąd systemu. ".$mail->ErrorInfo;
$tab_Lost["icon"]="error";
$tab_Lost["btn_text"]="OK";
}
}
ob_end_clean();
echo json_encode($tab_Lost);
} else {
echo "No data.";
}
?>