Advertisement
Guest User

security

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