-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcsrf_change_password.php
105 lines (87 loc) · 3.51 KB
/
csrf_change_password.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
include "includer.php";
$message="";
$newconn = new ConnectDB($sn,$un,$pss,$db);
if(isset($_REQUEST['action']) && isset($_REQUEST['password_new']) && isset($_REQUEST['password_conf'])){
$password_new = $_REQUEST["password_new"];
$password_conf = $_REQUEST["password_conf"];
if($password_new == ""){
$message = "<font color=\"red\">Please enter a new password...</font>";
}
else{
if($password_new != $password_conf){
$message = "<font color=\"red\">The passwords don't match!</font>";
}
else{
$login = $_SESSION['login'];
$password_new = hash("sha1",$password_new,false);
if($slc=="1" or $slc=="2"){
if(isset($_REQUEST['password_curr'])){
$password_curr = $_REQUEST["password_curr"];
$password_curr = hash("sha1",$password_curr,false);
$sql = "SELECT password FROM users WHERE name='$login' AND password='$password_curr'";
$stmt = $newconn->conn->prepare($sql);
if(!$stmt){
die("Error:".$stmt->errorInfo());
}
else{
$stmt->execute();
if($stmt->rowCount()!=0){
$sql = "UPDATE users SET password='$password_new' WHERE name='$login'";
$stmt=$newconn->conn->prepare($sql);
if(!$stmt){
die("Error:".$stmt->errorInfo());
}
else{
$stmt->execute();
$message = "<font color='green'>The password has been changed!</font>";
}
}
else{
$message="<font color='red'>Wrong the current password!</font>";
}
}
}
else{
$message="<font color='red'>Enter the current password!</font>";
}
}
else{#$slc='0'
$sql = "UPDATE users SET password='$password_new' WHERE name='$login'";
$stmt=$newconn->conn->prepare($sql);
if(!$stmt){
die("Error:".$stmt->errorInfo());
}
else{
$stmt->execute();
$message = "<font color='green'>The password has been changed!</font>";
}
}
}
}
}
$newconn->disconnectServer();
?>
<div class="container" id="main">
<h1>CSRF (Cross Site Reference Forgery) - (Change Password)</h1>
<p>Change your password.</p>
<form action="<?php echo($_SERVER["SCRIPT_NAME"]); ?>" method="GET">
<?php
if($slc == "1" or $slc == "2"){
?>
<p><label for="password_curr">Current password:</label><br />
<input type="password" id="password_curr" name="password_curr"></p>
<?php
}
?>
<p><label for="password_new">New password:</label><br />
<input type="password" id="password_new" name="password_new"></p>
<p><label for="password_conf">Re-type new password:</label><br />
<input type="password" id="password_conf" name="password_conf"></p>
<button type="submit" name="action" value="change">Change</button>
</form>
<br />
<?php
echo $message;
?>
</div>