-
Notifications
You must be signed in to change notification settings - Fork 1
/
change_password.php
156 lines (132 loc) · 5.16 KB
/
change_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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php include 'session.php'; ?>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<style>
#sidebar{position:relative;margin-top:-20px}
#content{position:relative;margin-left:210px}
@media screen and (max-width: 600px) {
#content {
position:relative;margin-left:auto;margin-right:auto;
}
}
</style>
</head>
<?php
include 'conn.php';
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) {
?>
<body style="color:black">
<div id="header">
<?php include 'header.php';
?>
</div>
<div id="sidebar">
<?php
$active="";
include 'sidebar.php'; ?>
</div>
<div id="content">
<div class="content-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12 lg-12 sm-12">
<h1 class="page-title">Change Password</h1>
</div>
</div>
<div class="row">
<div class="col-md-10">
<div class="panel panel-default">
<div class="panel-heading">Password Fields</div>
<div class="panel-body">
<form method="post" name="chngpwd" class="form-horizontal">
<div class="form-group" method="post">
<label class="col-sm-4 control-label">Current Password</label>
<div class="col-sm-8">
<input type="password" class="form-control" name="currpassword" id="password" required>
</div>
</div>
<div class="hr-dashed"></div>
<div class="form-group">
<label class="col-sm-4 control-label">New Password</label>
<div class="col-sm-8">
<input type="password" class="form-control" name="newpassword" id="newpassword" required>
</div>
</div>
<div class="hr-dashed"></div>
<div class="form-group">
<label class="col-sm-4 control-label">Confirm Password</label>
<div class="col-sm-8">
<input type="password" class="form-control" name="confirmpassword" id="confirmpassword" required>
</div>
</div>
<div class="hr-dashed"></div>
<div class="form-group">
<div class="col-sm-8 col-sm-offset-4">
<button class="btn btn-primary" name="submit" type="submit">Save changes</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php
if(isset($_POST["submit"])){
$username=$_SESSION['username'];
$password=mysqli_real_escape_string($conn,$_POST["currpassword"]);
$sql="select * from admin_info where admin_username='$username'";
$result=mysqli_query($conn,$sql) or die("query failed.");
if(mysqli_num_rows($result)>0)
{
while($row=mysqli_fetch_assoc($result)){
if($password==$row['admin_password']){
$newpassword=mysqli_real_escape_string($conn,$_POST["newpassword"]);
$confpassword=mysqli_real_escape_string($conn,$_POST["confirmpassword"]);
if($newpassword==$confpassword)
{
if($newpassword!=$password)
{
$sql1="UPDATE admin_info set admin_password='{$newpassword}' where admin_username='{$username}'";
$result1=mysqli_query($conn,$sql1) or die("query failed.");
echo '<div class="alert alert-success alert_dismissible"><button type="button" class="close" data-dismiss="alert">×</button><b> Password Changed Successfully.</b></div>';
}
else {
echo '<div class="alert alert-info alert_dismissible"><button type="button" class="close" data-dismiss="alert">×</button><b>New Password Can not be same as Current Password..</b></div>';
}
}
else {
echo '<div class="alert alert-warning alert_dismissible"><button type="button" class="close" data-dismiss="alert">×</button> <b>New Password and Confirm Password Not Matched!</b></div>';
}
}
else {
echo '<div class="alert alert-danger alert_dismissible"><button type="button" class="close" data-dismiss="alert">×</button><b> Current Password not matched!</b></div>';
}
}
}
}
?>
<?php
}
else {
echo '<div class="alert alert-danger"><b> Please Login First To Access Admin Portal.</b></div>';
?>
<form method="post" name="" action="login.php" class="form-horizontal">
<div class="form-group">
<div class="col-sm-8 col-sm-offset-4" style="float:left">
<button class="btn btn-primary" name="submit" type="submit">Go to Login Page</button>
</div>
</div>
</form>
<?php }
?>
</div>
</div>
</div>
</body>
</html>