Advertisement
Guest User

lock

a guest
May 16th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.80 KB | None | 0 0
  1. --os.pullEvent = os.pullEventRaw
  2. local monitor = peripheral.find("monitor")
  3. pro = shell.getRunningProgram()
  4. credentialsFile = pro.."SAM"
  5. userInput = ""
  6. passInput = ""
  7. promptInput = ""
  8. local function lock()
  9.   if fs.exists(credentialsFile) then
  10.     local file = fs.open(credentialsFile, "r")
  11.     user = file.readLine(1)
  12.     pass = file.readLine(2)
  13.     prompt = file.readLine(3)
  14.     file.close()
  15.   end
  16.   -------------------------------------
  17.   if prompt == nil then
  18.     term.clear()
  19.     term.setCursorPos(1,1)
  20.     textutils.slowPrint("Hello, what would you like your username to be?")
  21.     term.setTextColor(colors.yellow)
  22.     userInput = read()
  23.     term.setTextColor(colors.white)
  24.     textutils.slowPrint("Hello "..userInput..". \nWhat would you like your password to be?")
  25.     term.setTextColor(colors.yellow)
  26.     passInput = read()
  27.     term.setTextColor(colors.white)
  28.     textutils.slowPrint("What would you like your message to say before \ndisplaying your login prompt?")
  29.     term.setTextColor(colors.yellow)
  30.     promptInput = read()
  31.     term.setTextColor(colors.white)
  32.     -------------------------------------
  33.     if not fs.exists(credentialsFile) then
  34.       local file = fs.open(credentialsFile, "w")
  35.       file.write(userInput)
  36.       file.write("\n"..passInput)
  37.       file.write("\n"..promptInput)
  38.       file.close()
  39.     end
  40.     -------------------------------------
  41.     textutils.slowPrint("Okay, setup finished. Rebooting in 2 seconds")
  42.     sleep(2)
  43.     os.reboot()
  44.   end
  45.   -------------------------------------
  46.   if peripheral.find("monitor") then
  47.     monitor.setTextScale(5)
  48.     monitor.setBackgroundColor(colors.red)
  49.     monitor.clear()
  50.     monitor.setCursorPos(6,5)
  51.     monitor.write("Locked")
  52.   end
  53.   -------------------------------------
  54.   term.clear()
  55.   term.setCursorPos(1,1)
  56.   term.setTextColor(colors.yellow)
  57.   textutils.slowPrint(prompt)
  58.   term.setTextColor(colors.white)
  59.   sleep(1)
  60.   textutils.slowWrite("Username: ")
  61.   input1= term.setTextColor(colors.yellow)
  62.   input1 = read()
  63.   term.setTextColor(colors.white)
  64.   textutils.slowWrite("Password: ")
  65.   input2 = term.setTextColor(colors.yellow)
  66.   input2 = read("*")
  67.   if user == input1 and pass == input2 then
  68.     if peripheral.find("monitor") then
  69.       monitor.setTextScale(5)
  70.       monitor.setBackgroundColor(colors.green)
  71.       monitor.clear()
  72.       monitor.setCursorPos(5,5)
  73.       monitor.write("Unlocked")
  74.     end
  75.     term.setTextColor(colors.green)
  76.     term.setCursorPos(1,4)
  77.     textutils.slowPrint("Valid Login Credentials. Welcome to the System.")
  78.     sleep(2)
  79.     term.clear()
  80.     term.setCursorPos(1,1)
  81.     term.setTextColor(colors.yellow)
  82.     print(os.version())
  83.     term.setCursorPos(1,2)
  84.   else
  85.     term.setCursorPos(1,4)
  86.     term.setTextColor(colors.red)
  87.     textutils.slowPrint("Invalid Login Credenials, Please Don't Try Again.")
  88.     sleep(2)
  89.     lock()
  90.   end
  91. end
  92. local function isStartup()
  93.   if not fs.exists("startup") then
  94.     local file = fs.open("startup", "w")
  95.     file.write("shell.run(\"")
  96.     file.write(pro)
  97.     file.write("\")")
  98.     file.close()
  99.     os.reboot()
  100.   else
  101.     local file = fs.open("startup", "r")
  102.     local readFile = file.readAll()
  103.     file.close()
  104.     if not string.find(readFile,"shell.run") then
  105.       term.clear()
  106.       term.setCursorPos(1,1)
  107.       term.setTextColor(colors.red)
  108.       textutils.slowPrint("You already have a startup.\nWould you like to delete it (y/n)?")
  109.       local input = read()
  110.       if input == "y" then
  111.         textutils.slowPrint("Deleting startup.")
  112.         fs.delete("startup")
  113.         sleep(1)
  114.         term.clear()
  115.         term.setCursorPos(1,1)
  116.         term.setTextColor(colors.white)
  117.         textutils.slowPrint("Finished, now reloading")
  118.         sleep(1)
  119.         isStartup()
  120.       end
  121.     end
  122.   end
  123. end
  124.  
  125. isStartup()
  126. lock()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement