-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathforgotpwd.php
101 lines (87 loc) · 3.17 KB
/
forgotpwd.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
<?php
/*
@author: Ademcan ([email protected])
@name: forgotpwd.php
@description: Renew password page
*/
session_start();
require_once("./config.php");
$lng = language();
switch ($lng) {
case "en":
require("./en.php");
break;
case "fr":
require("./fr.php");
break;
}
?>
<html>
<head>
<link rel="icon" type="image/jpg" href="images/favicon.png">
<link rel="stylesheet" href="css/flat.css" type="text/css" media="screen" />
<title>Login canSnippet</title>
</head>
<body>
<div id="loginWindow">
<img src="images/canSnippetLogoBlack.png" style="width:70px; height:60px;float:left;"/>
<br><h2><?php echo($messages['forgotpwdtitle']); ?></h2><br>
<form method="POST" >
<table>
<tr><td width="200px">Email:</td><td> <input class="login" type="email" name="email" ></td></tr>
</table>
<input type="submit" value="<?php echo($messages['forgotpwdbutton']); ?>" class="loginButton" />
</form>
</div>
<center>
</body>
<html>
<?php
// send email to the user to renew pwd
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$dbname='snippets.sqlite';
if(!class_exists('SQLite3'))
die("SQLite 3 NOT supported.");
$base=new SQLite3($dbname);
$email = $_POST['email'];
// check if email exists in DB
$count_query = "SELECT count(*) AS count FROM user WHERE email=\"".$email."\" ";
$results_count = $base->query($count_query);
$row_count = $results_count->fetchArray();
$snippets_count = $row_count['count'];
$username = $_POST['username2'];
if($snippets_count>0){
// generate unique token
$randomNum=substr(str_shuffle("0123456789abcdefghijklmnopqrstvwxyz"), 0, 16);
// save token to token table
$date = date("Y-m-d H:i:s");
$addToken = "INSERT INTO pwdtoken(email, token, timestamp) VALUES ('$email', '$randomNum' , '$date' )";
$base->exec($addToken);
// Send email to user
$from = "canSnippet"; // this is the sender's Email address
$subject = "".$messages['newpwdmailsubject']."";
$rawurl = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$url = explode('/', $rawurl );
array_pop($url);
$url2=implode("/",$url);
$message = "".$messages['newpwdmailbody']."".$url2."/renewpwd.php?token=".$randomNum."";
$header_array = [
"MIME-Version: 1.0",
"Content-type: text/plain; charset=UTF-8",
"From: ".$from."",
];
$headers = implode("\r\n", $header_array);
mail($email,$subject,$message,$headers);
?>
<script>
location.href = 'thankyou.php';
</script>
<?php
}
else{
?>
<script>alert("<?php echo($messages['emailaddresserror']); ?>")</script>
<?php
}
}
?>