-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchangepassword.php
More file actions
133 lines (81 loc) · 2.88 KB
/
changepassword.php
File metadata and controls
133 lines (81 loc) · 2.88 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
<?php
session_start();
require 'connect.php';
require 'functions.php';
if(isset($_POST['update'])) {
$oldpass = clean($_POST['oldpass']);
$newpass = clean($_POST['newpass']);
$confirmpass = clean($_POST['confirmpass']);
$query = "SELECT password FROM students WHERE password = '$oldpass'";
$result = mysqli_query($con, $query);
if(mysqli_num_rows($result) > 0) {
if($newpass == $confirmpass) {
$query = "UPDATE students SET password = '$newpass' WHERE id='".$_SESSION['userid']."'";
if($result = mysqli_query($con, $query)) {
$_SESSION['prompt'] = "Password updated.";
$_SESSION['password'] = $newpass;
header("location:profile.php");
exit;
} else {
die("Error with the query");
}
} else {
$_SESSION['errprompt'] = "The new passwords you entered doesn't match.";;
}
} else {
$_SESSION['errprompt'] = "You've entered a wrong old password.";
}
}
if(isset($_SESSION['username'], $_SESSION['password'])) {
?>
<!DOCTYPE html>
<html>
<head>
<title>Change Password - Student Information System</title>
<link href="bootstrap.min.css" rel="stylesheet">
<link href="main.css" rel="stylesheet">
</head>
<body>
<?php include 'header.php'; ?>
<section>
<div class="container">
<strong class="title">Change Password</strong>
</div>
<div class="edit-form box-left clearfix">
<?php
if(isset($_SESSION['errprompt'])) {
showError();
}
?>
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST">
<div class="form-group">
<label for="oldpass">Old Password</label>
<input type="password" class="form-control" name="oldpass" placeholder="Old Password" required>
</div>
<div class="form-group">
<label for="newpass">New Password</label>
<input type="password" class="form-control" name="newpass" placeholder="New Password" required>
</div>
<div class="form-group">
<label for="confirmpass">Confirm Password</label>
<input type="password" class="form-control" name="confirmpass" placeholder="Confirm Password" required>
</div>
<div class="form-footer">
<a href="profile.php">Go back</a>
<input class="btn btn-primary" type="submit" name="update" value="Update Password">
</div>
</form>
</div>
</section>
<script src="jquery-3.1.1.min.js"></script>
<script src="bootstrap.min.js"></script>
<script src="main.js"></script>
</body>
</html>
<?php
} else {
header("location:profile.php");
}
unset($_SESSION['errprompt']);
mysqli_close($con);
?>