· 6 months ago · Apr 08, 2025, 10:50 AM
1-- Required Imports
2local libs = require("libs")
3--
4
5--verables
6local password_true = "God"
7--
8-- Define the "main" function
9-- This is the function we want to "protect"
10local function main()
11 local hash_ = "7a0c0b6d"
12
13 if checkFileHash("disk/authenticate", hash_) then
14 --sleep(0.2)
15 else
16 term.clear() -- clears the terminal
17 term.setCursorPos(1,1) -- sets cursor postion
18
19 printError("Security Check Failed! - Shutdown") -- prints a error message
20 sleep(5) -- sleeps for 5 seconds
21 os.shutdown() -- shutdown CraftOS
22 end
23
24 while true do
25 term.clear()
26 term.setCursorPos(1, 1)
27 write("Password:")
28 local password = read("*")
29
30 if password == password_true then
31 return
32 else
33 printError("Incorrect password.")
34 sleep(2)
35 end
36 end
37end
38
39local leaveloop = true
40while leaveloop do
41 local ok, err = pcall(main) -- protectedly call main
42
43 if ok then
44 -- Correct password was entered!
45 -- do whatever you want here
46 term.clear()
47 term.setCursorPos(1, 1)
48 shell.run("src_main.lua")
49 leaveloop = false
50 else
51 -- There was an error! The contents of the error are stored in "err"
52 if err == "Terminated" then
53 printError("\nSorry, but we can't have you terminating this now can we?")
54 pcall(sleep, 2) -- pcall the sleep function since it is also terminateable.
55 end
56 end
57end