Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions SQLInjectionExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Security Vulnerability #3757
// The below code is for the security vulnerability that has been programmed by me in java itself. You can simply convert my code to your preferred programming language and then edit it and after that use it.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;

public class SQLInjectionExample {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter username: ");
String username = scanner.nextLine();

System.out.print("Enter password: ");
String password = scanner.nextLine();

try {
// Connect to the database
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase", "root", "password");
Statement statement = connection.createStatement();

// Vulnerable SQL query (user inputs are not sanitized)
String query = "SELECT * FROM users WHERE username = '" + username + "' AND password = '" + password + "'";

ResultSet resultSet = statement.executeQuery(query);

// Checking if login is successful
if (resultSet.next()) {
System.out.println("Login successful!");
} else {
System.out.println("Login failed!");
}

connection.close();
} catch (Exception e) {
e.printStackTrace();
}
scanner.close();
}
}
Loading