Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local allowedFile = "allowed_users"
- -- Funzione XOR per criptare/decriptare
- local function xorCrypt(str, key)
- local res = {}
- for i = 1, #str do
- local k = string.byte(key, ((i - 1) % #key) + 1)
- local c = string.byte(str, i)
- table.insert(res, string.char(bit.bxor(c, k)))
- end
- return table.concat(res)
- end
- -- Carica utenti
- local function loadAllowed()
- if not fs.exists(allowedFile) then return {} end
- local f = fs.open(allowedFile, "r")
- local enc = f.readAll()
- f.close()
- local dec = xorCrypt(enc, "passwordchiave")
- local t = textutils.unserialize(dec)
- return t or {}
- end
- -- Salva utenti
- local function saveAllowed(list)
- local data = textutils.serialize(list)
- local enc = xorCrypt(data, "passwordchiave")
- local f = fs.open(allowedFile, "w")
- f.write(enc)
- f.close()
- end
- -- Password menu
- local function login()
- write("Inserisci password operatore: ")
- local pass = read("*")
- return pass == "tommy2805"
- end
- if not login() then
- print("Accesso negato.")
- return
- end
- local allowed = loadAllowed()
- while true do
- print("\n=== MENU OPERATORE ===")
- print("1. Mostra utenti consentiti")
- print("2. Aggiungi utente")
- print("3. Rimuovi utente")
- print("4. Esci")
- write("Scelta: ")
- local c = read()
- if c == "1" then
- print("\nUtenti autorizzati:")
- for i, u in ipairs(allowed) do
- print(i .. ". " .. u)
- end
- elseif c == "2" then
- write("Nome utente da aggiungere: ")
- local newUser = read()
- table.insert(allowed, newUser)
- saveAllowed(allowed)
- print("Utente aggiunto.")
- elseif c == "3" then
- print("Utenti:")
- for i, u in ipairs(allowed) do
- print(i .. ". " .. u)
- end
- write("Numero da rimuovere: ")
- local n = tonumber(read())
- if n and allowed[n] then
- table.remove(allowed, n)
- saveAllowed(allowed)
- print("Utente rimosso.")
- else
- print("Scelta non valida.")
- end
- elseif c == "4" then
- print("Uscita dal menu.")
- break
- else
- print("Scelta non valida.")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment