-
Notifications
You must be signed in to change notification settings - Fork 0
/
resetpass.php
executable file
·116 lines (101 loc) · 2.89 KB
/
resetpass.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
<?php
require_once("session.php");
require_once("class.user.php");
$auth_user = new USER();
$user_id = $_SESSION['user_session'];
$stmt = $auth_user->runQuery("SELECT *
FROM users
WHERE user_id=:user_id");
$stmt->execute(array(":user_id"=>$user_id));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
if($auth_user)
{
if(isset($_POST['submit']))
{
$old_pass = ($_POST["old_pass"]);
$auth_user = new USER();
$user_id = $_SESSION['user_session'];
$stmt = $auth_user->runQuery("SELECT *
FROM users
WHERE user_id=:user_id");
$stmt->execute(array(":user_id"=>$user_id));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
$new_pass = ($_POST["new_pass"]);
$confirm_new_pass = ($_POST["confirm_new_pass"]);
if(strlen($new_pass) < 6)
{
$error[] = "Password must be at least 6 characters";
}
else if(password_verify($old_pass, $userRow['user_pass']))
{
if($new_pass == $confirm_new_pass)
{
$auth_user->resetpass($user_id,$new_pass,$confirm_new_pass);
}
else
{
$error[] = "New password doesn't match";
}
}
else
{
$error[] = "Old password doesn't match";
}
}
else
{
$error[] = "Please enter the password.";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Password reset </title>
<link rel="stylesheet" href="index.css" type="text/css" />
</head>
<body class="normal">
<h1 class="top_reset">Hello ! <?php echo $userRow['user_name'] ?> you are here to reset your password.</h1>
<form method="post" class="form_reset">
<h2>Change password</h2>
<div class="error">
<?php
if(isset($error))
{
foreach($error as $error)
{
?>
<?php echo $error; ?>
<?php
}
}
else
{
?>
Successfully changed Go back to <a href='homepage.php' class="a">home page</a> here
<?php
}
?>
</div>
<br>
<div class="required" >
Current password :<br>
<input type="txt" name="old_pass" class="user_input" placeholder="Old Password" required />
</div>
<div class="required" >
New password :<br>
<input type="password" name="new_pass" class="user_input" placeholder="New Password" required />
</div>
<div class="required" >
Reenter new password :<br>
<input type="password" name="confirm_new_pass" class="user_input" placeholder="Confirm New Password" required />
</div>
<button type="submit" name="submit" class="submit" value='Change password'> Save changes </button>
or
<button class="submit">
<a href="homepage.php" class="b"> Keep my old password </a>
</button>
</form>
</body>
</html>