MySQL + SQL · Lesson 109

SQL Injection और Prevention

SQL Injection क्या है?

SQL injection एक attack है जहाँ hacker input field में SQL code type करके database को उसे चलाने के लिए धोखा देता है। यह सबसे common web vulnerabilities में से एक है।

यह कैसे होता है

अगर login query strings जोड़कर बनती है: user ' OR '1'='1 type करके password check bypass कर सकता है। खतरा user input को सीधे SQL में मिलाना है।

Fix: Prepared Statements

// PHP PDO - safe
$stmt = $pdo->prepare("SELECT * FROM users WHERE email = ?");
$stmt->execute([$email]);
? placeholder user input को data रखता है, कभी runnable SQL नहीं — injection block।

सारांश

  • SQL injection input fields से attacker SQL चलाता है।
  • Prepared statements / parameterized queries से रोकें — user input को SQL में कभी न जोड़ें।
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 लाइव कोड एडिटर

इस पेज के प्रोग्राम यहीं तैयार हैं — चलाएँ, बदलें और सीखें। कुछ भी इंस्टॉल किए बिना।
OneCompiler द्वारा संचालित। कोड एडिटर में अपने आप आ जाता है — Run दबाकर आउटपुट देखें। अगर एडिटर न खुले तो नए टैब में खोलें.