Hdb / Jsnsj.js
Hxbzbb7272's picture
Create Jsnsj.js
a1c872c verified
Raw
History Blame Contribute Delete
1.83 kB
const http = require("http");
const url = require("url");
// Generate 4-digit PIN
const PIN = Math.floor(1000 + Math.random() * 9000);
// Create server
const server = http.createServer((req, res) => {
const parsed = url.parse(req.url, true);
// API: verify PIN
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");
}
}
// Serve HTML page
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>
`);
});
// Start server
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("=================================");
});