Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local devKey = "3575e50cc6635311078014a550bc3f9f"
- term.clear()
- term.setCursorPos(1,1)
- -- limit read function
- local function limitRead(limX, rChar)
- term.setCursorBlink(true)
- local origX, origY = term.getCursorPos()
- local returnString = ""
- while true do
- local xPos, yPos = term.getCursorPos()
- local event, p1, p2 = os.pullEvent()
- if event == "char" then
- returnString = returnString..p1
- if not rChar then
- if not limX then
- term.setTextColor(colors.blue)
- write(p1)
- else
- if string.len(returnString) >= limX then
- term.setTextColor(colors.blue)
- term.setCursorPos(origX, origY)
- write(string.sub(returnString, (string.len(returnString)-limX)+1))
- elseif string.len(returnString) < limX then
- term.setTextColor(colors.blue)
- write(p1)
- end
- end
- else
- if not limX then
- term.setTextColor(colors.blue)
- write(rChar)
- else
- if string.len(returnString) >= limX then
- term.setTextColor(colors.blue)
- term.setCursorPos(origX, origY)
- write(string.rep(rChar, limX))
- elseif string.len(returnString) < limX then
- term.setTextColor(colors.blue)
- write(rChar)
- end
- end
- end
- elseif event == "key" and p1 == 14 then --backspace
- returnString = string.sub(returnString, 1, (string.len(returnString))-1)
- term.setCursorPos(xPos-1,yPos)
- term.setTextColor(colors.blue)
- write(" ")
- term.setCursorPos(origX, origY)
- if string.len(returnString) >= limX then
- if not rChar then
- term.setTextColor(colors.blue)
- write(string.sub(returnString, (string.len(returnString)-limX)+1))
- else
- term.setTextColor(colors.blue)
- write(string.rep(rChar,limX))
- end
- else
- if not rChar then
- term.setTextColor(colors.blue)
- write(returnString)
- else
- term.setTextColor(colors.blue)
- write(string.rep(rChar, string.len(returnString)))
- end
- end
- elseif event == "key" and p1 == 15 then --tab
- break
- elseif event == "key" and p1 == 28 then --enter
- break
- end
- end
- term.setCursorBlink(false)
- return returnString
- end
- -- End limitRead() --
- -- Start loginScript() --
- local function loginScript()
- paintutils.drawLine(10,6,40,6, colors.blue)
- term.setCursorPos(10, 6)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.blue)
- write("Please login")
- for i = 1, 7 do
- paintutils.drawLine(10, 6 + i, 40, 6 + i, colors.lightGray)
- end
- local loginObjects = {
- {name = "Username:",
- nameX = 11,
- nameY = 9,
- color = colors.black,
- BGcolor = colors.lightGray},
- {name = "Username: ",
- nameX = 21,
- nameY = 9,
- color = colors.white,
- BGcolor = colors.white},
- {name = "Password:",
- nameX = 11,
- nameY = 11,
- color = colors.black,
- BGcolor = colors.lightGray},
- {name = "Password: ",
- nameX = 21,
- nameY = 11,
- color = colors.white,
- BGcolor = colors.white}
- }
- for i = 1, #loginObjects do
- term.setCursorPos(loginObjects[i].nameX, loginObjects[i].nameY)
- term.setTextColor(loginObjects[i].color)
- term.setBackgroundColor(loginObjects[i].BGcolor)
- write(loginObjects[i].name)
- end
- term.setCursorPos(22, 9)
- while true do
- username = limitRead(16)
- if username ~= "TEMP_USER" then
- print(username)
- break
- end
- end
- term.setCursorPos(22, 11)
- while true do
- password = limitRead(16, "*")
- if password ~= "TEMP_PASSWORD" then
- print(password)
- break
- end
- end
- local response = http.post(
- "http://pastebin.com/api/api_login.php", "api_dev_key="..textutils.urlEncode(devKey).."&api_user_name="..textutils.urlEncode(username).."&api_user_password="..textutils.urlEncode(password)
- ).readAll()
- local badRequests = {
- "Bad API request, invalid login",
- "Bad API request, account not active"
- }
- if response then
- term.setCursorPos(1,1)
- term.setTextColor(colors.white)
- print(response)
- if sResponse == badRequests[1] then
- term.setCursorPos(11,7)
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colors.red)
- write("Invalid login!")
- end
- end
- end
- loginScript()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement