-
Notifications
You must be signed in to change notification settings - Fork 2
/
change_pass.php
119 lines (100 loc) · 4.01 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
<?php
session_start();
include 'Connection.php';
include 'login/login_check.php';
$data = is_logged($con);
?>
<?php
if($data){
$ID = $data["ID"];/* userid of the user */
}
?>
<?php
$oldpass = $newpass = $conpass = $message = "";
$oldpasserr = $newpasserr = $conpasserr= "";
if($_SERVER['REQUEST_METHOD']=='POST'){
$oldpass = test_data($_REQUEST["oldpass"]);
$newpass = test_data($_REQUEST["newpass"]);
$conpass = test_data($_REQUEST["conpass"]);
if($newpass!=$conpass){
$conpasserr = "*Password Doesn't Match";
}
if(empty($newpasserr) && empty($conpasserr) &&empty($oldpasserr)){
//--Check Duplicate--
$sql = "SELECT * FROM customers where ID='$ID'";
$result = $con->query($sql);
while($row = $result->fetch_assoc()){
if(($row["Password"]==$oldpass) && ($newpass==$conpass))
{
$sql="UPDATE customers SET Password='$newpass' where ID='$ID'";
$query_run=mysqli_query($con,$sql);
if($query_run)
{
$message = "Password Changed Sucessfully";
header('location: profile.php?msg=1');
}
else
{
$message = "Password is not correct";
header("location: change_pass.php?msg=error");
}
}else{
if($row["Password"]!=$oldpass){
$oldpasserr = "Old Password Doesn't match";
}else{
header("location: change_pass.php?msg=error");
}
}
}
}
}
function test_data($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="../../fontawesome/css/fontawesome.min.css">
<link rel="stylesheet" href="../../fontawesome/css/all.css">
<script src="../../fontawesome/js/fontawesome.min.js"></script>
<link rel="stylesheet" href="css/changepss.css">
<title>Change password</title>
</head>
<body class="password">
<div class="password-in">
<h2>Change your password</h2>
<div>
<?php
if(isset($_GET['msg']) && $_GET['msg']==1){
echo "*Password Changed Sucessfully";
}else if(isset($_GET['msg']) && $_GET['msg']=="error"){
echo "*Password is not correct";
} ?>
</div>
<hr>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="oldPass">
<i class="fas fa-lock" id="icon"></i>
<input type= "password" class="input-box" placeholder="Enter your old Password" name="oldpass" size="25" required>
<span class="error"><br><?php echo $oldpasserr;?></span>
</div>
<div class="newPass">
<i class="fas fa-lock" id="icon"></i>
<input type= "password" class="input-box" placeholder="Enter your new Password" name="newpass" size="25" required>
</div>
<div class="conPass">
<i class="fas fa-lock" id="icon"></i>
<input type= "password" class="input-box" placeholder="Confirm Password" name="conpass" size="25" required>
<span class="error"><br><?php echo $conpasserr;?></span>
</div>
<hr>
<input type="submit" value="submit" class="submit">
<hr>
</form>
</div>
</body>
</html>