| const http = require("http"); |
| const url = require("url"); |
|
|
| |
| const PIN = Math.floor(1000 + Math.random() * 9000); |
|
|
| |
| const server = http.createServer((req, res) => { |
| const parsed = url.parse(req.url, true); |
|
|
| |
| if (parsed.pathname === "/verify") { |
| const userPin = parsed.query.pin; |
|
|
| if (userPin == PIN) { |
| res.writeHead(200, { "Content-Type": "text/plain" }); |
| return res.end("OK"); |
| } else { |
| res.writeHead(403, { "Content-Type": "text/plain" }); |
| return res.end("Wrong PIN"); |
| } |
| } |
|
|
| |
| res.writeHead(200, { "Content-Type": "text/html" }); |
| res.end(` |
| <!DOCTYPE html> |
| <html> |
| <head> |
| <title>PIN Login</title> |
| <style> |
| body { font-family: Arial; text-align:center; margin-top:50px; } |
| input, button { padding:10px; font-size:16px; } |
| </style> |
| </head> |
| <body> |
| |
| <h2>π Enter 4-digit PIN</h2> |
| <input id="pin" placeholder="PIN"> |
| <button onclick="login()">Enter</button> |
| |
| <p id="msg"></p> |
| |
| <div id="content" style="display:none;"> |
| <h1>β
Access Granted</h1> |
| <p>π Server is running on 127.0.0.1:8080</p> |
| </div> |
| |
| <script> |
| async function login() { |
| const pin = document.getElementById("pin").value; |
| |
| const res = await fetch("/verify?pin=" + pin); |
| const text = await res.text(); |
| |
| if (res.ok) { |
| document.getElementById("content").style.display = "block"; |
| document.getElementById("msg").innerText = ""; |
| } else { |
| document.getElementById("msg").innerText = text; |
| } |
| } |
| </script> |
| |
| </body> |
| </html> |
| `); |
| }); |
|
|
| |
| server.listen(8080, "127.0.0.1", () => { |
| console.log("================================="); |
| console.log("π Server running"); |
| console.log("π http://127.0.0.1:8080"); |
| console.log("π PIN:", PIN); |
| console.log("================================="); |
| }); |