-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.php
104 lines (81 loc) · 2.49 KB
/
module.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Registration Form</title>
<link rel="stylesheet" href="module.css" />
</head>
<body>
<h1>Login is successful <br></h1>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
//Connection to DB
$conn = mysqli_connect("localhost", "root", "", "final_project2", "3308");
/*
//To use whilst implementing Escaping solution
$username = mysqli_real_escape_string($conn, $_POST["username"]);
$password = mysqli_real_escape_string($conn, $_POST["password"]);
*/
$username = $_POST["username"];
$password = $_POST["password"];
// Injectable code
$sql = "SELECT Username, Password FROM customers where Username = '$username' AND Password = '$password'";
$result = mysqli_query($conn, $sql);
$count = mysqli_num_rows($result);
/*
//Fixed solution 1 Prepared Statements
$stmt = mysqli_stmt_init($conn);
$sql = "SELECT Username, Password FROM customers WHERE Username = ? AND Password = ?";
if (mysqli_stmt_prepare($stmt, $sql))
mysqli_stmt_bind_param($stmt, "ss", $username, $password);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$count = mysqli_num_rows($result);
*/
/*
//Fixed solution 2 stored procedures
$stmt = mysqli_stmt_init($conn);
$sql = "CALL Get_User('$username', '$password');";
if (mysqli_stmt_prepare($stmt, $sql))
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$count = mysqli_num_rows($result);
*/
/*
// Fixed solution 3 prepared statements and stored procedures
$stmt = mysqli_stmt_init($conn);
$sql = "CALL get_login(?, ?);";
if (mysqli_stmt_prepare($stmt, $sql)) {
mysqli_stmt_bind_param($stmt, "ss", $username, $password);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$count = mysqli_num_rows($result);
}
*/
/*
//Fixed solution 4 with escaped values
$sql = "SELECT Username, Password FROM customers WHERE Username = '$username' AND Password = '$password'";
$result = mysqli_query($conn, $sql);
$count = mysqli_num_rows($result);
*/
if($count > 0)
{
while($row = $result->fetch_assoc()) {
echo "<h2>" . "<br>" . "Welcome " . $row["Username"]. " " . "<br>" . "</h2>" . "<p>" . "</p>";
}
}
else {
header("Location: modulenosignin.html");
}
mysqli_close($conn);
}
?>
<form method="post" action="inputvalidation.php">
<input type="submit" value="Buy Mice" />
</form>
<form method="post" action="logout.php">
<input type="submit" value="Logout" />
</form>
</body>
</html>