-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchanged.php
More file actions
118 lines (102 loc) · 3.13 KB
/
Copy pathchanged.php
File metadata and controls
118 lines (102 loc) · 3.13 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
<?php
session_start();
if (!isset($_SESSION['username'])) {
$_SESSION['msg'] = "You must log in first";
header('location: login.php');
}?>
<?php include('server.php') ?>
<?php
//initializing connection
$host=" ";
$dbuser=" ";
$dbpassword=" ";
$dbname=" ";
$conn = mysqli_connect($host, $dbuser, $dbpassword, $dbname) or die("Connection Error: " . mysqli_error($conn));
if (isset($_POST['changepassword'])) {
// receive all input values from the form
$password_1 = mysqli_real_escape_string($db, $_POST['newPassword']);
$password_2 = mysqli_real_escape_string($db, $_POST['confirmPassword']);
// form validation: ensure that the form is correctly filled ...
// by adding (array_push()) corresponding error unto $errors array
if (empty($password_1)) { array_push($errors, "Password is required"); }
if ($password_1 != $password_2) {
array_push($errors, "The two passwords do not match");
}
if (count($_POST) > 0) {
$result = mysqli_query($conn, "SELECT * from `users` WHERE username='" . $_SESSION["username"] . "'");
$row = mysqli_fetch_array($result);
if (count($errors) == 0) {
if (md5($_POST["currentPassword"]) == $row["password"]) {
mysqli_query($conn, "UPDATE `users` set password='" . md5($_POST["newPassword"]) . "' WHERE username='" . $_SESSION["username"] . "'");
$_SESSION['changed'] = "Your password is changed sucessfully";
} else
{
array_push($errors, "Current Password doesnot match");
}
}
}
}
?>
<html>
<head>
<title>Change Password</title>
<link rel="icon" href="img/logo.png" type="image/png" />
<link rel="stylesheet" type="text/css" href="style.css" />
<style>
.bck{
width: 95%;
text-decoration-color: white;
padding: 10px;
font-size color: white;
background: tomato ;
border: none;
border-radius: 5px;
}
.bck:hover{
background:red;
}
a{
text-decoration:none;
color:black;
}
</style>
</head>
<body>
<div class="header">
<h2>Change Password</h2>
</div>
<form method="post" action="">
<div class="contenttwo">
<!-- notification message -->
<?php if (isset($_SESSION['changed'])) : ?>
<div class="error success" >
<h3>
<?php
echo $_SESSION['changed'];
unset($_SESSION['changed']);
?>
</h3>
</div>
<?php endif ?>
</div>
<?php include('errors.php'); ?>
<div class="input-group">
<label>Current Password:</label>
<input type="password" name="currentPassword" />
</div>
<div class="input-group">
<label>New Password</label>
<input type="password" name="newPassword" />
</div>
<div class="input-group">
<label>Confirm Password</label>
<input type="password" name="confirmPassword" />
</div>
<div class="input-group">
<input type="submit" name="changepassword" value="Submit" class="btn">
</div>
<p><button class="bck"><a href="index.php" style = "color:black" >
Back</a> </button> </p>
</form>
</body>
</html>