<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Moses Ikechukwu</title>
    <description>The latest articles on DEV Community by Moses Ikechukwu (@moses_ikechukwu_20d1ebe40).</description>
    <link>https://dev.to/moses_ikechukwu_20d1ebe40</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2896811%2F1556eb51-9289-4518-b5b1-0c639a9d6e1d.png</url>
      <title>DEV Community: Moses Ikechukwu</title>
      <link>https://dev.to/moses_ikechukwu_20d1ebe40</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/moses_ikechukwu_20d1ebe40"/>
    <language>en</language>
    <item>
      <title>SQL Injection</title>
      <dc:creator>Moses Ikechukwu</dc:creator>
      <pubDate>Mon, 24 Feb 2025 17:25:57 +0000</pubDate>
      <link>https://dev.to/moses_ikechukwu_20d1ebe40/sql-injection-514k</link>
      <guid>https://dev.to/moses_ikechukwu_20d1ebe40/sql-injection-514k</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is SQL Injection?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SQL Injection (SQLi) is a web security vulnerability that allows attackers to manipulate a website’s database by injecting malicious SQL code into input fields. It can lead to unauthorized access, data theft, modification, or even complete deletion of a database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How SQL Injection Works&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When a web application improperly handles user input, an attacker can insert SQL commands into a query. For example, consider this vulnerable PHP code:&lt;/p&gt;

&lt;p&gt;$username = $_POST['username'];&lt;br&gt;
$password = $_POST['password'];&lt;br&gt;
$query = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";&lt;br&gt;
$result = mysqli_query($conn, $query);&lt;/p&gt;

&lt;p&gt;If an attacker enters admin' -- as the username, the query becomes:&lt;/p&gt;

&lt;p&gt;SELECT * FROM users WHERE username = 'admin' --' AND password = ''&lt;/p&gt;

&lt;p&gt;The -- comment operator ignores the rest of the statement, bypassing authentication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Consequences of SQL Injection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Unauthorized Access&lt;/em&gt; – Attackers can log in as admin without credentials.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Data Theft&lt;/em&gt; – Sensitive user information, including passwords, can be exposed.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Data Manipulation&lt;/em&gt; – Hackers can modify or delete database records.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;System Compromise&lt;/em&gt; – In severe cases, an attacker can gain full control of the server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Preventing SQL Injection&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use Prepared Statements and Parameterized Queries:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;$stmt = $conn-&amp;gt;prepare("SELECT * FROM users WHERE username = ? AND password = ?");&lt;br&gt;
$stmt-&amp;gt;bind_param("ss", $username, $password);&lt;br&gt;
$stmt-&amp;gt;execute();&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Sanitize User Input – Use htmlspecialchars() to prevent special character interpretation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use Least Privilege Principle – Restrict database user permissions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Employ Web Application Firewalls (WAF) – Detect and block SQL injection attempts.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SQL Injection is one of the most dangerous web vulnerabilities but can be prevented with secure coding practices. By using parameterized queries, input validation, and proper access control, developers can protect applications from SQLi attacks.&lt;/p&gt;

</description>
      <category>php</category>
      <category>sql</category>
      <category>sqlinjection</category>
      <category>security</category>
    </item>
  </channel>
</rss>
