-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange-p.php
66 lines (53 loc) · 1.61 KB
/
change-p.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
<?php
session_start();
if (isset($_SESSION['id']) && isset($_SESSION['user_name'])) {
include "db_conn.php";
if (isset($_POST['op']) && isset($_POST['np'])
&& isset($_POST['c_np'])) {
function validate($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$op = validate($_POST['op']);
$np = validate($_POST['np']);
$c_np = validate($_POST['c_np']);
if(empty($op)){
header("Location: change-password.php?error=Old Password is required");
exit();
}else if(empty($np)){
header("Location: change-password.php?error=New Password is required");
exit();
}else if($np !== $c_np){
header("Location: change-password.php?error=The confirmation password does not match");
exit();
}else {
// hashing the password
$op = md5($op);
$np = md5($np);
$id = $_SESSION['id'];
$sql = "SELECT password
FROM users WHERE
id='$id' AND password='$op'";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) === 1){
$sql_2 = "UPDATE users
SET password='$np'
WHERE id='$id'";
mysqli_query($conn, $sql_2);
header("Location: change-password.php?success=Your password has been changed successfully");
exit();
}else {
header("Location: change-password.php?error=Incorrect password");
exit();
}
}
}else{
header("Location: change-password.php");
exit();
}
}else{
header("Location: index.php");
exit();
}