Skip to content

Commit 231de05

Browse files
committed
Introduced support for piggybacked queries
1 parent 69011de commit 231de05

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ version: '3.8'
22
services:
33
web:
44
build: .
5+
container_name: sqli-example-web
56
ports:
67
- "8080:80"
78
depends_on:
89
- db
910

1011
db:
1112
image: mysql:5.7
13+
container_name: sqli-example-db
1214
environment:
1315
MYSQL_ROOT_PASSWORD: rootpassword
1416
MYSQL_DATABASE: sqli_db

src/home.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
<link rel="stylesheet" href="assets/styles.css">
2626
</head>
2727
<body>
28-
<div class="container mt-5">
29-
<h1 class="text-center">Welcome!</h1>
30-
<div class="text-center mt-4">
31-
<p>You have successfully logged in</p>
28+
<div class="login-container">
29+
<div class="login-box">
30+
<h1 class="text-center">Welcome, <?php echo $username?>!</h1>
31+
<div class="text-center mt-4">
32+
<p>You have successfully logged in</p>
33+
</div>
3234
</div>
3335
</div>
3436

src/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
<?php endif ?>
3131
<div class="form-group mb-3">
3232
<label for="username">Username</label>
33-
<input type="text" class="form-control" name="username" placeholder="Enter username" required>
33+
<input type="text" class="form-control" name="username" placeholder="Enter username" autocomplete="off">
3434
</div>
3535
<div class="form-group mb-3">
3636
<label for="password">Password</label>
37-
<input type="password" class="form-control" name="password" placeholder="Enter password" required>
37+
<input type="password" class="form-control" name="password" placeholder="Enter password" autocomplete="off">
3838
</div>
3939
<div class="d-grid mt-3">
4040
<button type="submit" class="btn btn-primary btn-block">Login</button>

src/login.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,30 @@
2020
$user = $_POST['username'];
2121
$pass = $_POST['password'];
2222

23-
// Verifica che i campi non siano vuoti
24-
if (empty($user) || empty($pass)) {
25-
$_SESSION['error'] = "Username and password cannot be empty.";
26-
header("Location: index.php");
27-
exit();
28-
}
29-
3023
// Query SQL vulnerabile a SQL Injection
3124
$sql = "SELECT * FROM users WHERE username = '$user' AND password = '$pass'";
32-
$result = $conn->query($sql);
3325

34-
if ($result->num_rows > 0) {
35-
$_SESSION['success'] = "Login successful!";
36-
header("Location: home.php");
26+
// multi_query per supportare query multiple (piggybacked queries)
27+
if ($conn->multi_query($sql)) {
28+
do {
29+
// Store first result set
30+
if ($result = $conn->store_result()) {
31+
if ($result->num_rows > 0) {
32+
$_SESSION['success'] = "Login successful!";
33+
$_SESSION['username'] = $user;
34+
header("Location: home.php");
35+
} else {
36+
$_SESSION['error'] = "Invalid username or password.";
37+
header("Location: index.php");
38+
}
39+
$result->free();
40+
}
41+
// Prepare for the next result set
42+
} while ($conn->next_result());
3743
} else {
38-
$_SESSION['error'] = "Invalid username or password.";
3944
header("Location: index.php");
4045
}
46+
4147

4248
$conn->close();
4349
exit();

0 commit comments

Comments
 (0)