diff --git a/backend/index.js b/backend/index.js index 24e262e..a82863b 100644 --- a/backend/index.js +++ b/backend/index.js @@ -15,11 +15,22 @@ app.post('/api/login', (req, res) => { const query = `SELECT * FROM users WHERE username = '${username}' AND password = '${password}'`; db.query(query, (err, results) => { - if (err) return res.status(500).send('Error'); + if (err) { + return res.status(500).json({ + message: 'Error', + query: query + }); + } if (results.length > 0) { - res.send('Login successful'); + res.json({ + message: 'Login successful', + query: query + }); } else { - res.status(401).send('Invalid credentials'); + res.status(401).json({ + message: 'Invalid credentials', + query: query + }); } }); }); diff --git a/frontend/src/pages/SQLInjection.jsx b/frontend/src/pages/SQLInjection.jsx index 8bc23c7..3d55a58 100644 --- a/frontend/src/pages/SQLInjection.jsx +++ b/frontend/src/pages/SQLInjection.jsx @@ -1,20 +1,24 @@ -import React, { useState } from 'react'; -import { Card, Container, Form, Button, Alert } from 'react-bootstrap'; +import React, { useState } from "react"; +import { Card, Container, Form, Button, Alert } from "react-bootstrap"; export default function SQLInjection() { - const [username, setUsername] = useState(''); - const [password, setPassword] = useState(''); - const [msg, setMsg] = useState(''); + const [username, setUsername] = useState(""); + const [password, setPassword] = useState(""); + const [msg, setMsg] = useState(""); + const [status, setStatus] = useState(null); + const [query, setQuery] = useState(""); + const [showQuery, setShowQuery] = useState(false); const handleLogin = async () => { - const res = await fetch('http://localhost:5000/api/login', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ username, password }) + const res = await fetch("http://localhost:5000/api/login", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ username, password }), }); - - const text = await res.text(); - setMsg(text); + const data = await res.json(); + setStatus(res.status); + setMsg(data.message); + setQuery(data.query); }; return ( @@ -30,14 +34,22 @@ export default function SQLInjection() {