added password oth

This commit is contained in:
miles committed 2026-03-25 02:55:31 +04:00
1 parent ef88655bad
commit 2099599770
2 files changed
+36 -23

No files matched your search

+24 -18
View File
@@ -1,36 +1,42 @@
import requests
import sys
import getpass # This hides the password as you type
def start_calculator():
print("--- Welcome to the Calculator ---")
print("\n--- Calculator Unlocked ---")
try:
num1 = float(input("Enter first number: "))
op = input("Enter operator (+, -, *, /): ")
num2 = float(input("Enter second number: "))
if op == "+": print(f"Result: {num1 + num2}")
elif op == "-": print(f"Result: {num1 - num2}")
elif op == "*": print(f"Result: {num1 * num2}")
elif op == "/": print(f"Result: {num1 / num2}")
else: print("Invalid operator.")
except ValueError:
print("Please enter valid numbers.")
# ... (rest of your math logic)
print(f"Result: {num1 + num2}") # Simplified example
except Exception as e:
print(f"Error: {e}")
def check_server():
url = "http://localhost:6000/status"
try:
response = requests.get(url)
data = response.json()
if data.get("run") == "yes":
print("Access granted by server.")
start_calculator()
print("--- Server Authentication ---")
password = getpass.getpass("Enter Server Password: ")
try:
# Send the password in the headers
headers = {'x-password': password}
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
if data.get("run") == "yes":
start_calculator()
else:
print("Server is set to 'no'. Access denied.")
elif response.status_code == 401:
print("Access Denied: Incorrect Password.")
else:
print("Access denied: The server said 'no'.")
sys.exit()
print(f"Server returned status code: {response.status_code}")
except requests.exceptions.ConnectionError:
print("Error: Could not connect to the server. Is it running?")
print("Could not connect to server.")
if __name__ == "__main__":
check_server()
+12 -5
View File
@@ -2,14 +2,21 @@ const express = require('express');
const app = express();
const PORT = 6000;
// Change this variable to "no" to stop the Python script
let accessGranted = "no";
// Set your desired password here
const SERVER_PASSWORD = "hi";
let accessGranted = "yes";
app.get('/status', (req, res) => {
res.json({ run: accessGranted });
// Look for 'x-password' in the request headers
const clientPassword = req.headers['x-password'];
if (clientPassword === SERVER_PASSWORD) {
res.json({ run: accessGranted, message: "Authenticated!" });
} else {
res.status(401).json({ run: "no", message: "Invalid Password" });
}
});
app.listen(PORT, () => {
console.log(`Server is running at http://localhost:${PORT}`);
console.log(`Current status: ${accessGranted}`);
console.log(`Server running. Password is required to launch calculator.`);
});