Advertisement
Guest User

lock

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