Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- state = 0
- name = ""
- pass = ""
- pass2 = ""
- username = true
- password = false
- password2 = false
- --Functions
- 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 e=="key_up" and p1==keys.enter
- if state == 1 then
- username = false
- else
- term.setCursorBlink(false)
- return input
- end
- if username == false then
- password = true
- else
- term.setCursorBlink(false)
- return input
- end
- if password == false then
- password2 = true
- else
- term.setCursorBlink(false)
- return input
- end
- end
- drawImage = function()
- term.setBackgroundColor(colors.lightBlue)
- clear()
- rUser = paintutils.loadImage("/system/res/rUser")
- paintutils.drawImage(rUser, 1, 2)
- term.setCursorPos(19,12)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.lightGray)
- term.write("Username")
- term.setCursorPos(19,14)
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colors.gray)
- term.write("Password")
- term.setCursorPos(19,16)
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colors.gray)
- term.write("Confirm Pass")
- end
- info = function()
- while true do
- e, button, x, y = os.pullEvent()
- if state == 0 and e == "mouse_up" and button == 1 and x >= 19 and x <= 32 and y == 12 then
- paintutils.drawLine(19,12, 32, 12, colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(19,12)
- name = readN()
- userN = name
- if userN == userN then
- state = 1
- username = false
- password = true
- end
- end
- if state == 1 and password == true then
- paintutils.drawLine(19,14, 32,14, colors.white)
- term.setTextColor(colors.lightGray)
- term.setCursorPos(19,14)
- pass = readN(12, "#")
- userP = pass
- if userP == userP then
- state = 2
- password = false
- password2 = true
- end
- end
- while password2 == true do
- if state == 2 and password2 == true then
- paintutils.drawLine(19,16, 32,16, colors.white)
- term.setTextColor(colors.lightGray)
- term.setCursorPos(19,16)
- pass2 = readN(12, "#")
- userP2 = pass2
- if userP2 == userP then
- file = fs.open("/system/users/user_profile", "w")
- file.writeLine(userN)
- file.writeLine(userP2)
- file.close()
- shell.run("/system/firmware")
- else
- term.setCursorPos(34,16)
- term.setTextColor(colors.red)
- term.setBackgroundColor(colors.lightBlue)
- print("Didn't match")
- file.close()
- fs.delete("/system/users/user_profile")
- file2 = fs.open("/system/users/user_profile", "w")
- file2.close()
- sleep(1)
- term.setCursorPos(34,16)
- term.setTextColor(colors.red)
- term.setBackgroundColor(colors.lightBlue)
- print(" ")
- end
- end
- end
- end
- end
- clear = function()
- term.clear()
- term.setCursorPos(1,1)
- end
- start = function()
- state = 0
- name = ""
- pass = ""
- username = true
- password = false
- password2 = false
- drawImage()
- info()
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement