Advertisement
GhastlyDoMinic

Password lockout Screen. init_code.lua

Apr 8th, 2025 (edited)
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.41 KB | None | 0 0
  1. -- Required Imports
  2. local libs = require("libs")
  3. --
  4.  
  5. --verables
  6. local password_true = "God"
  7. --
  8. -- Define the "main" function
  9. -- This is the function we want to "protect"
  10. local 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.         pcall(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.       pcall(sleep, 5)
  35.     end
  36.   end
  37. end
  38.  
  39. local leaveloop = true
  40. while 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.       leaveloop = true
  55.       pcall(sleep, 2) -- pcall the sleep function since it is also terminateable.
  56.     end
  57.   end
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement