forked from Sajibekanti/SecureWEBApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassreset.php
More file actions
49 lines (36 loc) · 1.25 KB
/
Copy pathpassreset.php
File metadata and controls
49 lines (36 loc) · 1.25 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
<?php
include ("config.php");
$token=mysqli_real_escape_string($db,$_GET['token']);
$user=mysqli_real_escape_string($db,$_GET['user']); // read values from GET request
$pass=mt_rand();
$count=0;
$sql="select email from reset where token='$token'"; //getting email
$result=mysqli_query($db, $sql) or die('Error querying database.');
//fetch values from database
if($row = mysqli_fetch_array($result)) {
$checkemail=$row['email'];
$count=1;
}
$sql="select username from register where email='$checkemail'"; //getting username
$result=mysqli_query($db, $sql) or die('Error querying database.');
//fetch values from database
if($row = mysqli_fetch_array($result)) {
$checkuser=$row['username'];
}
if($count==1 && $checkuser==$user ) //checking valid link or not and also username
{
$query = "Update register set password='$pass' where username='$user' AND email='$checkemail'";
if (mysqli_query($db, $query)==1)
{
echo '<h2>Your new new password is '.$pass.'</h2>';
$sql1="delete from reset where token='$token'";
mysqli_query($db,$sql1) or die ('Error querying db');
}
else{
echo "<h2>Error changing password or invalid reset link</h2>";
}
}
else{
echo "<h2>Invalid reset link</h2>";
}
?>