-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings_script.php
More file actions
37 lines (29 loc) · 1.11 KB
/
settings_script.php
File metadata and controls
37 lines (29 loc) · 1.11 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
<?php
// This page updates the user password
require("includes/common.php");
if (!isset($_SESSION['email'])) {
header('location: index.php');
}
$oldpassword= MD5(mysqli_escape_string($con,filter_input(INPUT_POST, 'oldpassword')));
$newpassword= MD5(mysqli_escape_string($con,filter_input(INPUT_POST, 'newpassword')));
$password= MD5(mysqli_escape_string($con,filter_input(INPUT_POST, 'password')));
$query = "SELECT email, password FROM users WHERE email ='" . $_SESSION['email'] . "'";
$result = mysqli_query($con, $query)or die($mysqli_error($con));
$row = mysqli_fetch_array($result);
$orig_pass = $row['password'];
if ($newpassword != $password)
{
header('location: settings.php?error=The two passwords don\'t match');
}
else
{
if ($oldpassword == $orig_pass) {
$query = "UPDATE users SET password = '" . $newpassword . "' WHERE email = '" . $_SESSION['email'] . "'";
mysqli_query($con, $query) or die($mysqli_error($con));
header('location: settings.php?error=Password Updated');
} else
{
header('location: settings.php?error=Wrong Old Password');
}
}
?>