-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheditpassword.php
More file actions
116 lines (113 loc) · 3.8 KB
/
editpassword.php
File metadata and controls
116 lines (113 loc) · 3.8 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
<?php
session_start();
require_once('./connect.php');
if(isset($_SESSION['login'])){
if($_SESSION['login']){
if(isset($_SESSION['username'])){
if(isset($_POST['submit'])){
$opassword = $_POST['opassword'];
$npassword = $_POST['npassword'];
$ncpassword = $_POST['ncpassword'];
$query = "SELECT password FROM login WHERE username = '".$_SESSION['username']."';";
$result = mysqli_query($con, $query);
if(mysqli_num_rows($result) == 0){
$_SESSION['status'] = "Internal Error1";
header("Location: editpassword.php");
exit();
}
$row = mysqli_fetch_assoc($result);
echo $row['password']." ".$opassword." ".$npassword." ".$ncpassword;
if($row['password'] == $opassword){
// check for both passwordss to be same
if($ncpassword == $npassword){
$query = "UPDATE login
SET password = '".$npassword."'
WHERE username= '".$_SESSION['username']."';";
$result = mysqli_query($con, $query);
if($result == True){
$_SESSION['status'] = "Password Changed Successfullly";
header("Location: home.php");
exit();
} else {
$_SESSION['status'] = "Internal Error2";
header("Location: editpassword.php");
exit();
}
} else {
$_SESSION['status'] = "New Password Don't Match";
header("Location: editpassword.php");
exit();
}
} else {
$_SESSION['status'] = "Wrong Password Entered";
header("Location: editpassword.php");
exit();
}
} else {
// create a form
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/opensanslight.css" />
<link rel = "stylesheet" href="css/style.css" type="text/css">
<title>Blogging System | Edit Password</title>
</head>
<body>
<div class="container">
<div id="head-navbar">
<div id="logo" class="menu inline">
<h3 style="margin:0px;">Blogging System</h3>
</div>
<div class="menu inline pull-right">
<a class="btn btn-info" href="home.php">Back</a>
</div>
</div>
<div class="row give-top-margin">
<div class="col-sm-6 col-sm-offset-3">
<form method="post" action="editpassword.php">
<div class="form-group">
<label for="username">Password</label>
<input type="password" name="opassword" class="form-control" placeholder="Enter Password" required />
</div>
<div class="form-group">
<label for="username">New Password</label>
<input type="password" name="npassword" class="form-control" placeholder="Enter New Password" required />
</div>
<div class="form-group">
<label for="username">Confirm Password</label>
<input type="password" name="ncpassword" class="form-control" placeholder="Confirm Password" required />
</div>
<button type="submit" name="submit" class="btn btn-primary" value="reset">Reset Password</button>
<?php
if(isset($_SESSION['status'])){
echo '<h4 class="center-text">'.$_SESSION['status'].'</h4>';
unset($_SESSION['status']);
}
?>
</form>
<br>
</div>
</div>
</div>
<script src="js/jquery.js"></script>
<script src="js/bootstrap.js"></script>
<script type="text/javascript" src="js/script.js"></script>
</body>
</html>
<?php
}
} else {
header("Location: logout.php");
exit();
}
}
} else {
$_SESSION['wrong'] = "You are logged out.";
header("Location: index.php");
exit();
}
?>