Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
local USERS_FILE = "allowed_users" local PASS_FILE = "operator_pass" local function load_allowed() if fs.exists(USERS_FILE) then local fh = fs.open(USERS_FILE, "r") local content = fh.readAll() fh.close() local ok, t = pcall(textutils.unserialize, content) if ok and type(t) == "table" then return t end end return {} end local function save_allowed(tbl) local fh = fs.open(USERS_FILE, "w") fh.write(textutils.serialize(tbl)) fh.close() end local function read_password(prompt) term.write(prompt) -- read masked input local pass = read("*") print() return pass end local function load_pass() if fs.exists(PASS_FILE) then local fh = fs.open(PASS_FILE, "r") local p = fh.readAll() fh.close() return p end return nil end local function save_pass(p) local fh = fs.open(PASS_FILE, "w") fh.write(p) fh.close() end -- Login / impostazione password local stored = load_pass() if not stored then print("Nessuna password impostata. Impostane una ora.") local p1 = read_password("Nuova password: ") local p2 = read_password("Conferma password: ") if p1 == "" then print("Password vuota non permessa. Esco.") return end if p1 ~= p2 then print("Le password non coincidono. Esco.") return end save_pass(p1) stored = p1 print("Password impostata correttamente.") end local attempt = read_password("Password operatore: ") if attempt ~= stored then print("Password errata. Accesso negato.") return end -- Se qui, autenticato local users = load_allowed() local function list_users() if #users == 0 then print("[Nessun utente consentito]") return end print("Utenti consentiti:") for i, u in ipairs(users) do print(string.format("%d) %s", i, u)) end end local function add_user() term.write("Nome utente da aggiungere: ") local name = read() if name == "" then print("Nome vuoto, annullo.") return end for _, v in ipairs(users) do if v == name then print("Utente giĆ presente.") return end end table.insert(users, name) save_allowed(users) print("Utente '"..name.."' aggiunto.") end local function remove_user() term.write("Nome utente da rimuovere: ") local name = read() if name == "" then print("Nome vuoto, annullo.") return end for i, v in ipairs(users) do if v == name then table.remove(users, i) save_allowed(users) print("Utente '"..name.."' rimosso.") return end end print("Utente non trovato.") end local function change_password() local p = read_password("Nuova password: ") local p2 = read_password("Conferma nuova password: ") if p == "" then print("Password vuota non permessa.") return end if p ~= p2 then print("Le password non coincidono.") return end save_pass(p) print("Password aggiornata.") end -- Menu principale while true do print("\n--- Menu Operatore ---") print("1) Elenca utenti") print("2) Aggiungi utente") print("3) Rimuovi utente") print("4) Cambia password") print("5) Esci") term.write("> ") local choice = read() if choice == "1" then list_users() elseif choice == "2" then add_user() elseif choice == "3" then remove_user() elseif choice == "4" then change_password() elseif choice == "5" then print("Uscita.") break else print("Scelta non valida.") end end
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)