Question: Figure 5 Explain why the code given in Figure 5 above , is vulnerable to SQL Injection and cross-site scripting attacks. Give an example scenario

Figure 5

$servername = "localhost";

$username = "me";

$password = "!myPa$$";

$dbname = "mydb";

if(isset($_POST["uname"], $_POST["upass"])) {

$conn = new mysqli($servername, $username, $password, $dbname);

if (!$conn->connect_error) {

die("Connection failed: " . $conn->connect_error);

}

$query = "select * from user where uname='$_POST[uname]' AND upass='$_POST[upass]'";

$result = $conn->query($query);

}

?>

Explain why the code given in Figure 5 above, is vulnerable to SQL Injection and cross-site scripting attacks.

Give an example scenario to demonstrate your analysis in the previous question.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!