Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function centerPrint(text,y)
- if y == nil then y = 1 end
- local dx, dy = term.getSize()
- term.setCursorPos(dx/2-#text/2,y)
- print(text)
- end
- local istyping = true
- local input = ""
- local printoutput = input
- local pchar = "x"
- local charlimit = 30
- local password = "password"
- function setPrintOutput()
- printoutput = input
- if #printoutput > charlimit then
- printoutput = printoutput:sub(#printoutput-charlimit,#printoutput)
- end
- if #input > 1 then
- printoutput = ""
- for i=1 , #input-1 do
- printoutput = printoutput.."x"
- end
- printoutput = printoutput..input:sub(#input,#input)
- end
- end
- if term.isColor() then
- while istyping do
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.cyan)
- term.clear()
- term.setCursorPos(1,1)
- centerPrint("Login System",8)
- centerPrint("-=-=-=-=-=-=-=-=-=-=-=-",9)
- setPrintOutput()
- term.setTextColor(colors.white)
- centerPrint(">"..printoutput.."<",11)
- local event, a1 = os.pullEventRaw()
- if event == "char" then
- local keypressed = a1
- input = input..keypressed
- elseif event == "key" then
- local keycode = a1
- if keycode == 14 then
- input = input:sub(1,#input-1)
- elseif keycode == 28 or input == password:sub(1, -2) then
- if input == password:sub(1, -2) then
- term.setTextColor(colors.lime)
- centerPrint("Access Granted!",13)
- redstone.setOutput("back", true)
- sleep(2)
- redstone.setOutput("back", false)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- sleep(4)
- os.reboot()
- else
- term.setTextColor(colors.orange)
- centerPrint("Access Denied!",13)
- sleep(2)
- input = ""
- end
- end
- end
- end
- else
- while istyping do
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- centerPrint("Login System",8)
- centerPrint("-=-=-=-=-=-=-=-=-=-=-=-",9)
- setPrintOutput()
- centerPrint(">"..printoutput.."<",11)
- local event, a1 = os.pullEventRaw()
- if event == "char" then
- local keypressed = a1
- input = input..keypressed
- elseif event == "key" then
- local keycode = a1
- if keycode == 14 then
- input = input:sub(1,#input-1)
- elseif keycode == 28 or input == password:sub(1, -2) then
- if input == password:sub(1, -2) then
- centerPrint("Access Granted!",13)
- redstone.setOutput("back", true)
- sleep(2)
- redstone.setOutput("back", false)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- sleep(4)
- os.reboot()
- else
- centerPrint("Access Denied!",13)
- sleep(2)
- input = ""
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment