gistlib
<!DOCTYPE html> <html> <head> <title>Login Form</title> </head> <body> <h2>Login Form</h2> <form id="loginForm"> <label for="username">Username:</label><br> <input type="text" id="username" name="username"><br> <label for="password">Password:</label><br> <input type="password" id="password" name="password"><br><br> <button type="submit">Login</button> </form> <p id="message"></p> <script> document.getElementById("loginForm").addEventListener("submit", function(event) { event.preventDefault(); const username = document.getElementById("username").value; const password = document.getElementById("password").value; fetch("/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username, password }) }) .then(response => response.json()) .then(data => { if(data.success) { document.getElementById("message").innerText = "Login successful"; } else { document.getElementById("message").innerText = "Login failed. Please try again."; } }); }); </script> </body> </html> 1367 chars42 lines
<!DOCTYPE html> <html> <head> <title>Login Form</title> </head> <body> <h2>Login Form</h2> <form id="loginForm"> <label for="username">Username:</label><br> <input type="text" id="username" name="username"><br> <label for="password">Password:</label><br> <input type="password" id="password" name="password"><br><br> <button type="submit">Login</button> </form> <p id="message"></p> <script> document.getElementById("loginForm").addEventListener("submit", function(event) { event.preventDefault(); const username = document.getElementById("username").value; const password = document.getElementById("password").value; fetch("/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username, password }) }) .then(response => response.json()) .then(data => { if(data.success) { document.getElementById("message").innerText = "Login successful"; } else { document.getElementById("message").innerText = "Login failed. Please try again."; } }); }); </script> </body> </html>
index.tsxconst express = require("express"); const bodyParser = require("body-parser"); const app = express(); const PORT = 3000; let users = [ { username: "admin", password: "password123" } ]; app.use(bodyParser.json()); app.post("/login", (req, res) => { const { username, password } = req.body; const user = users.find(user => user.username === username && user.password === password); if(user) { res.json({ success: true }); } else { res.json({ success: false }); } }); app.listen(PORT, () => { console.log(`Server is running on http://localhost:${PORT}`); }); 615 chars28 lines
const express = require("express"); const bodyParser = require("body-parser"); const app = express(); const PORT = 3000; let users = [ { username: "admin", password: "password123" } ]; app.use(bodyParser.json()); app.post("/login", (req, res) => { const { username, password } = req.body; const user = users.find(user => user.username === username && user.password === password); if(user) { res.json({ success: true }); } else { res.json({ success: false }); } }); app.listen(PORT, () => { console.log(`Server is running on http://localhost:${PORT}`); });
gistlibby LogSnag