-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings_script.php
36 lines (30 loc) · 1.18 KB
/
settings_script.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
<?php
// This page updates the user password
require("includes/common.php");
if (!isset($_SESSION['email'])) {
header('location: index.php');
}
$old_pass = $_POST['old-password'];
$old_pass = mysqli_real_escape_string($con, $old_pass);
$old_pass = MD5($old_pass);
$new_pass = $_POST['password'];
$new_pass = mysqli_real_escape_string($con, $new_pass);
$new_pass = MD5($new_pass);
$new_pass1 = $_POST['password1'];
$new_pass1 = mysqli_real_escape_string($con, $new_pass1);
$new_pass1 = MD5($new_pass1);
$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 ($new_pass != $new_pass1) {
header('location: settings.php?error=The two passwords don\'t match');
} else {
if ($old_pass == $orig_pass) {
$query = "UPDATE users SET password = '" . $new_pass . "' 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');
}
?>