Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- -- [[ CENTER TEXT ]]
- function printcenter(sText)
- local w, h = term.getSize()
- local x, y = term.getCursorPos()
- x = math.max(math.floor((w / 2) - (#sText / 2)), 0)
- term.setCursorPos(x, y)
- print(sText)
- end
- -- [[ Login Func ]]
- function login()
- term.clear()
- term.setCursorPos(1,1)
- printcenter("Please enter your details")
- while true do
- term.setCursorPos(1,3)
- term.clearLine()
- write("Username: ")
- user = read()
- if user == "" then
- elseif user == keyw then
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- error()
- elseif user == username then break
- end
- end
- while true do
- term.setCursorPos(1,5)
- term.clearLine()
- write("Password: ")
- pass = read("*")
- if pass == "" then
- elseif pass == keyw then
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- error()
- elseif pass ~= keyw or password then break
- elseif pass == password then break
- end
- end
- -- [[ Accepting Password, Username ]]
- if user == username and pass == password then
- term.setCursorPos(1,7)
- term.setTextColor(colors.red)
- printcenter("Access granted.")
- rs.setOutput(side,true)
- sleep(3.5)
- rs.setOutput(side,false)
- os.reboot()
- else
- term.setCursorPos(1,7)
- term.setTextColor(colors.red)
- printcenter("Access denided.")
- printcenter("Please try again.")
- sleep(1.5)
- os.reboot()
- end
- end
- -- [[ Saving Func ]]
- function save(name,input)
- local file = fs.open("security/door/"..name,"w")
- file.writeLine(input)
- file.close()
- end
- -- [[ Load Func ]]
- function load(fileName)
- file = fs.open("security/door/"..fileName,"r")
- local line = file.readLine()
- file.close()
- return line or "none"
- end
- -- [[ Process func ]]
- function process()
- term.setCursorPos(1,13)
- printcenter("Processing your info, please wait.")
- sleep(1.5)
- term.setCursorPos(1,15)
- printcenter("Processing your info, please wait..")
- sleep(1.5)
- term.setCursorPos(1,17)
- printcenter("Done!")
- sleep(1)
- term.clear()
- term.setCursorPos(1,4)
- -- [[ Display input ]]
- print(" :------------------------:")
- print(" : Username: "..usern)
- print(" : ")
- print(" : Password: "..passw)
- print(" : ")
- if keyw == "" then print(" : Code: NONE")
- else print(" : Code: "..keyw)
- end
- print(" : ")
- print(" : Side: "..side)
- print(" :------------------------:")
- print("")
- print(" :---------: :----------:")
- print(" :Try again: : Continue :")
- print(" :---------: :----------:")
- -- [[ Buttons ]]
- while true do
- event, param, x,y = os.pullEvent("mouse_click")
- if event == "mouse_click" and (x >= 16 and x <= 24) and y == 15 then os.reboot() -- Button 1.
- elseif event == "mouse_click" and (x >= 30 and x <= 39) and y == 15 then -- Button 2.
- fs.makeDir("security/door/")
- save("info",usern) --Username
- save("password",passw) --Password
- save("side",side) --Door Side
- if keyw == "" then
- os.reboot()
- else
- save("keyw",keyw) --OS access code
- os.reboot()
- end
- end
- end
- end
- -- [[ Checking for first run ]]
- if not term.isColor() then
- print("Program requires an advanced computer.")
- return
- end
- term.setCursorPos(1,1)
- term.clear()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.red)
- term.clear()
- if fs.exists("security/door/info") then
- else
- term.setCursorPos(1,1)
- printcenter("This is your first run")
- term.setCursorPos(1,2)
- printcenter(" Please make a new account.")
- while true do
- term.setCursorPos(1,4)
- term.clearLine()
- write("Enter your username: ")
- usern = read()
- if usern == "" then
- else
- while true do
- term.setCursorPos(1,6)
- write("Enter your password: ")
- passw = read("*")
- if passw == "" then
- elseif passw == usern then
- term.setCursorPos(1,6)
- print("Password can't be same as username.")
- sleep(1.5)
- term.setCursorPos(1,6)
- term.clearLine()
- else
- term.setCursorPos(1,8)
- write("Debug Password(blank for none): ")
- keyw = read()
- while true do
- term.setCursorPos(1,10)
- print("Please enter door side(right,left,bottom,top)")
- term.setCursorPos(1,11)
- term.clearLine()
- write("Side: ")
- side = read()
- if side == "" then
- elseif side == "right" then process()
- elseif side == "left" then process()
- elseif side == "bottom" then process()
- elseif side == "top" then process()
- end
- end
- end
- end
- end
- end
- end
- -- [[ Run ]]
- os.pullEvent = os.pullEventRaw
- if fs.exists("security/door/keyw") then
- keyw = load("keyw")
- username = load("info")
- password = load("password")
- side = load("side")
- login()
- else
- username = load("info")
- password = load("password")
- side = load("side")
- login()
- end
Add Comment
Please, Sign In to add comment