-
Notifications
You must be signed in to change notification settings - Fork 1
/
reset-password.php
92 lines (90 loc) · 2.96 KB
/
reset-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
<?php
session_start();
$db=mysqli_connect('localhost','root','','dcms') or die("could not connect to database");
$msg = [];
$s = 0;
if(isset($_GET['key']) && isset($_GET['email']) && isset($_GET['action']) && $_GET['action'] == 'reset' && (!isset($_POST['reset_pass'])))
{
$z = "SELECT * from password_reset_temp where email='".$_GET['email']."' and key1='".$_GET['key']."'";
#echo $z;
$query = mysqli_query($db, $z);
$email1 = $_GET['email'];
if($query == false){
array_push($msg, "Invalid reset link");
}
else
$s = 1;
}
if(isset($_POST["reset_pass"])){
#echo "here2";
$error="";
$pass1 = mysqli_real_escape_string($db,$_POST["pass1"]);
$pass2 = mysqli_real_escape_string($db,$_POST["pass2"]);
$email = $_POST["email"];
$curDate = date("Y-m-d H:i:s");
if ($pass1==$pass2){
#echo "here";
$pass1 = hash('sha256',$pass1);
$q1= "UPDATE user SET `password`='".$pass1."' WHERE `email`='".$email."'";
#echo $q1;
mysqli_query($db, $q1);
$q2 = "DELETE FROM `password_reset_temp` WHERE `email`='".$email."'";
#echo $q2;
mysqli_query($db,$q2);
array_push($msg, '<h3 style="color:green; width:75%">Congratulations! Your password has been updated successfully.<br><a href="login.php">
Click here</a> to Login.</p></div><br />');
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Reset Password</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<link href="style10.css" type="text/css"rel="stylesheet"/>
<link href="https://fonts.googleapis.com/css?family=Montserrat:500&display=swap" rel="stylesheet">
<style>
.menu a{
color:white;
}
a{
color:dodgerblue;
}
</style>
</head>
<body>
<center>
<?php require_once("header.php");?>
<div class="content-section" style="width:70%">
<h3>Reset your password</h3><br><br>
<?php
if(sizeof($msg)>0)
{
foreach($msg as $m)
{
echo $m;
#echo "<h3 style='color:red; width:75%'>".$m."</h3><br>";
}
}
if($s){
$row = mysqli_fetch_assoc($query);
$expDate = $row['expDate'];
if ($expDate >= date("Y-m-d H:i:s")){
?>
<form action = '' method='post'>
<table>
<tr><th>Password</th><td><input type='password' name='pass1' maxlength="32" required></td></tr>
<tr><th>Confirm Password</th><td><input type='password' name='pass2' maxlength="32" required></td></tr>
<input type="hidden" name="email" value="<?php echo $email1;?>"/>
</table>
<br><input type='submit' name='reset_pass' value='Reset Password' class='example_e' style='width:50%'></form>
</div>
</center>
<?
}}?>
</body>
</html>