-
Notifications
You must be signed in to change notification settings - Fork 3
/
changePassword.php
84 lines (56 loc) · 2.36 KB
/
changePassword.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
if(isset($_POST['submitNewPassword'])){
$usernameChangePassword= $_POST['usernameChangePassword'] ;
$currentPass= $_POST['currentPass'] ;
$newPassword= $_POST['newPassword'] ;
$retypePassword= $_POST['retypePassword'] ;
$sqlSelect="SELECT * from `user` WHERE `username` = '$usernameChangePassword' AND `password` = '$currentPass'";
$result = mysqli_query($con,$sqlSelect);
$count = mysqli_num_rows($result);
if($count==1){
if($newPassword == $retypePassword){
$sql = "UPDATE `user` SET `password`='$newPassword' WHERE `username` = '$usernameChangePassword';";
$results = mysqli_query($con,$sql);
if ($results){
echo '<script>alert("Successful")</script>';
}
}
else{
echo '<script>alert("Passwords does not match. Please try again")</script>';
}
}
else{
echo '<script>alert("Incorrect current password")</script>';
}
}
if (isset($_GET['username']) && isset($_GET['currentPass']) && isset($_GET['newPassword']) && isset($_GET['retypePassword'])) {
include ("includes/connect.php");
$usernameChangePassword = $_GET['username'];
$currentPass = $_GET['currentPass'];
$newPassword = $_GET['newPassword'];
$retypePassword = $_GET['retypePassword'];
// echo $usernameChangePassword,$currentPass,$newPassword;
$sqlSelect="SELECT * from `user` WHERE `username` = '$usernameChangePassword' AND `password` = '$currentPass'";
$result = mysqli_query($con,$sqlSelect);
$count = mysqli_num_rows($result);
if($count==1){
if($newPassword == $retypePassword){
$sql = "UPDATE `user` SET `password`='$newPassword' WHERE `username` = '$usernameChangePassword';";
$results = mysqli_query($con,$sql);
if ($results){
echo '<script>alert("Successful")</script>';
header("location:http://192.168.5.243/srs/login.php?user=$usernameChangePassword&pass=$newPassword");
}
}
else{
echo '<script>alert("Passwords does not match. Please try again")</script>';
}
}
else{
echo '<script>alert("Incorrect current password")</script>';
}
} else {
$username = "not found";
$newPass = "not found";
}
?>