Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- state = 0
- username = true
- password = false
- --Function
- local readN = function(len, replaceChar)
- len = len or 12
- local input=""
- local key = 0
- term.setCursorBlink(true)
- repeat
- local e,p1= os.pullEvent()
- if e=="char" then
- if #input < len then
- input = input .. p1
- term.write(replaceChar or p1)
- end
- elseif e=="key" and p1==keys.backspace and #input > 0 then
- input = input:sub(1,#input-1)
- local x,y = term.getCursorPos()
- term.setCursorPos(x-1,y)
- term.write(" ")
- term.setCursorPos(x-1,y)
- end
- until p1==keys.enter
- term.setCursorBlink(false)
- return input
- end
- drawLogin = function()
- term.setBackgroundColor(colors.cyan)
- clear()
- image = paintutils.loadImage("/system/res/dUser")
- paintutils.drawImage(image, 15,4)
- term.setCursorPos(25, 5)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.lightGray)
- term.write("Username")
- term.setCursorPos(25, 7)
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colors.gray)
- term.write("Password")
- term.setCursorPos(47,18)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.red)
- print("O @")
- term.setCursorPos(48,18)
- term.setTextColor(colors.gray)
- print("|")
- end
- login = function()
- while username == true and state == 0 do
- e, button, x, y = os.pullEvent()
- if username == true and e == "mouse_up" and button == 1 and x >= 25 and x <= 36 and y == 5 then
- paintutils.drawLine(25,5, 36, 5, colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(25,5)
- name = readN()
- userN = name
- if userN == userN then
- file = fs.open("/system/users/user_profile", "r")
- if file.readLine() == userN then
- state = 1
- username = false
- password = true
- else
- file.close()
- term.setTextColor(colors.red)
- term.setBackgroundColor(colors.cyan)
- term.setCursorPos(25,8)
- print("Unknown Username:" .. userN)
- sleep(1)
- paintutils.drawLine(25,8, 51,8,colors.cyan)
- end
- end
- end
- end
- while password == true and state == 1 do
- e, button, x, y = os.pullEvent()
- if password == true and state == 1 then
- term.setCursorBlink(false)
- paintutils.drawLine(25,7, 36,7, colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(25,7)
- pass = readN(12, "#")
- userP = pass
- if userP == userP then
- file = fs.open("/system/users/user_profile", "r")
- file.readLine()
- if file.readLine() == userP then
- file.close()
- shell.run("/system/firmware")
- else
- file.close()
- term.setTextColor(colors.red)
- term.setBackgroundColor(colors.cyan)
- term.setCursorPos(25,8)
- print("Invalid Password!")
- sleep(1)
- paintutils.drawLine(25,8, 51,8,colors.cyan)
- end
- end
- end
- end
- end
- clear = function()
- term.clear()
- term.setCursorPos(1,1)
- end
- start = function()
- state = 0
- clear()
- drawLogin()
- login()
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement