-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange_pass.php
160 lines (148 loc) · 5.57 KB
/
change_pass.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
157
158
159
160
<?php
include("connection.php");
session_start();
//if user is not logged in
if(!isset($_SESSION['username'])){
header('location:login.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Book Exchange Website|Change Password</title>
<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://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<style>
.form-container {
display:table;
max-width:900px;
width:90%;
margin:0 auto;
box-shadow:100px 100px 100px 100px rgba(0,0,0,0.1);
}
form {
display:table-cell;
width:400px;
background-color:#ffffff;
padding:40px 60px 100px 60px;
color:#505e6c;
}
@media (max-width:991px) {
form {
padding:40px 40px 100px 40px;
}
}
form h2 {
font-size:30px;
line-height:1.5;
margin-bottom:30px;
}
form .form-control {
background:#f7f9fc;
border:none;
border-bottom:1px solid #dfe7f1;
border-radius:0;
box-shadow:none;
outline:none;
color:inherit;
text-indent:6px;
height:40px;
}
form .form-check {
font-size:13px;
line-height:20px;
}
form .btn-primary {
background:#f4476b;
border:none;
border-radius:4px;
padding:11px;
box-shadow:none;
margin-top:35px;
text-shadow:none;
outline:none !important;
}
form .btn-primary:hover, form .btn-primary:active, .btn-primary:active:hover {
background:#eb3b60;
}
</style>
</head>
<body>
<!-- Header -->
<?php
include 'navbar.php';
?>
<!-- /Header -->
<div class="form-container">
<form name="changePasswordForm" method="post" >
<h2 class="text-center">Change Password</h2>
<div class="form-group">
<b>Current Password :</b><br>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<input type="password" class="form-control" placeholder="Enter current password" name="currentpassword" required>
</div>
</div>
<div class="form-group">
<b>New Password :</b><br>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock" style="color:#f4476b;"></i></span>
<input type="password" class="form-control" placeholder="Enter new password" name="newpassword" id="password_1" required>
</div>
</div>
<div class="form-group">
<b>Confirm New Password :</b><br>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock" style="color:#f4476b;"></i></span>
<input type="password" class="form-control" placeholder="Enter new password again" name="confirmpassword" id="password_2" onkeyup=check() required>
</div>
</div><span id='message'></span>
<script>
var check = function() {
if (document.getElementById('password_1').value == document.getElementById('password_2').value) {
document.getElementById('message').style.color = 'green';
document.getElementById('message').innerHTML = 'Matching :)';
} else {
document.getElementById('message').style.color = 'red';
document.getElementById('message').innerHTML = 'Not Matching :(';
}
}
</script>
<div class="form-group">
<button class="btn btn-primary btn-block" name="change" type="submit">Change</button>
</div>
</form>
</div>
<?php
if(isset($_POST['change'])){
$username=$_SESSION['username'];
$currentpassword=$_POST['currentpassword'];
$newpassword=$_POST['newpassword'];
$result=mysqli_query($con, "SELECT * FROM user WHERE username='$username'");
$row=mysqli_fetch_array($result);
if($currentpassword==$row['password_1']){
mysqli_query($con, "UPDATE user SET password_1='$newpassword' WHERE username='$username' ");
?>
<script>
alert('Password changed');
window.location.replace('settings.php');
</script>
<?php
}else{
?>
<script>
alert('Current Password is incorrect.');
</script>
<?php
}
}
?>
<!-- Footer -->
<?php
include 'footer.php';
?>
<!-- /Footer -->
</body>