Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Coded by HPWebcamAble
- You need to use my Program Organizer to install this program
- You'll find the description there
- Program Requirements:
- -Advanced Computer
- Version: 1.2
- Notes:
- -Cleaned up the code a bit
- -Bug fixes
- -Ported to Advanced Computers
- ]]
- --Variables--
- w,h = term.getSize()
- args = {...}
- local cUser --The correct username
- local cPass --and password
- local uUser --The password and username entered by the user
- local uPass
- local codes = { --pastebin codes, or what to put in the file (only used with missing files)
- ["/password/bg"] = {"3Hsa4f63"},
- ["/password/login"] = {nil,"admin\nadmin"},
- ["/password/safemode"] = {nil,"true"}
- }
- --Functions--
- function color(txt,bck)
- if txt then
- term.setTextColor(txt)
- end
- if bck then
- term.setBackgroundColor(bck)
- end
- end
- function clear() shell.run("clear") end
- function tw(...) term.write(...) end
- function cp(...) term.setCursorPos(...) end
- function printC(text,y)
- if not y then
- error("printC:for text "..text..", y value expected")
- end
- tLenght = #tostring(text)
- local sStart = math.ceil(w/2-tLenght/2)
- local sEnd = sStart + tLenght
- cp(sStart,y)
- tw(text)
- return sStart,sEnd
- end
- function refreshLogin()
- f = fs.open("/password/login","r")
- if not f then
- color(colors.red)
- print("Failed to open login file")
- print("Try restarting Minecraft")
- return
- end
- cUser = f.readLine()
- cPass = f.readLine()
- f.close()
- end
- function scrollRead(x,y,maxX,insertText) --This basically scrolls but not very well
- if insertText then
- cPos = #insertText+1
- cInput = insertText
- else
- cPos = 1
- cInput = ""
- end
- term.setCursorBlink(true)
- while true do
- term.setCursorPos(x,y)
- term.write(string.rep(" ",maxX))
- term.setCursorPos(x,y)
- if string.len(cInput) > maxX-1 then
- term.write(string.sub(cInput,(maxX-1)*-1))
- else
- term.write(cInput)
- end
- if cPos > maxX-1 then
- term.setCursorPos(x+maxX-1,y)
- else
- term.setCursorPos(x+cPos-1,y)
- end
- if safeMode then --This is not usually part of this method, only for this program
- event,p1 = os.pullEvent()
- else
- event,p1 = os.pullEventRaw()
- end
- if event == "char" then
- cInput = string.sub(cInput,1,cPos)..p1..string.sub(cInput,cPos+1)
- cPos = cPos+1
- elseif event == "key" then
- if p1 == keys.enter then
- break
- elseif p1 == keys.backspace then
- if cPos > 1 then
- cInput = string.sub(cInput,1,cPos-2)..string.sub(cInput,cPos)
- cPos = cPos - 1
- end
- elseif p1 == keys["end"] then
- cPos = string.len(cInput)+1
- end
- end
- end
- term.setCursorBlink(false)
- return cInput
- end
- function get(sCode,sFile) --This function is a modified portion of the Pastebin program
- local sPath = shell.resolve( sFile )
- if fs.exists( sPath ) then
- return false
- end
- local response = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode( sCode ))
- if response then
- local sResponse = response.readAll()
- response.close()
- local file = fs.open( sPath, "w" )
- file.write( sResponse )
- file.close()
- return true
- else
- return false
- end
- end
- function main()--Having this as a function allows error catching
- if fs.exists("startup") then
- f = fs.open("startup","r")
- if f.readLine() ~= [[shell.run("pass elock")]] then
- if fs.exists("~startup") then
- shell.run("delete ~startup")
- else
- shell.run("rename startup ~startup")
- end
- end
- f.close()
- end
- f = fs.open("startup","w")
- f.write([[shell.run("pass elock")]])
- f.close()
- while true do
- color(nil,colors.white)
- clear()
- paintutils.drawImage(paintutils.loadImage("/password/bg"),1,1)
- color(colors.lightGray,colors.white)
- printC("Computer ID:"..os.getComputerID(),h)
- color(colors.black,colors.lightGray)
- cp(11,9)
- tw("Username:")
- cp(11,11)
- tw("Password:")
- color(colors.black,colors.white)
- if uUser then
- cp(20,9)
- tw(uUser)
- uPass = scrollRead(20,11,21)
- if uPass ~= cPass or uUser ~= cUser then
- uPass = nil
- uUser = nil
- color(colors.red,colors.lightGray)
- printC("Access denied",12)
- sleep(1)
- else
- break
- end
- else
- uUser = scrollRead(20,9,21)
- end
- end
- color(colors.yellow,colors.black)
- clear()
- print(os.version())
- color(colors.blue)
- print("Welcome")
- shell.run("delete startup")
- if fs.exists("~startup") then
- shell.run("rename ~startup startup")
- end
- end
- --Program--
- if w ~= 51 and h ~= 19 or not term.isColor() then
- print("This program can only run on an advanced computer")
- end
- for a,b in pairs(codes) do
- if not fs.exists(a) then
- color(colors.red)
- print("Missing "..a)
- if codes[a][1] then
- if not get(codes[a][1],a) then
- color(colors.red)
- print("Unable to download "..a.." from pastebin")
- return
- else
- color(colors.white)
- print("Downloaded "..a)
- end
- else
- f = fs.open(a,"w")
- f.write(codes[a][2])
- f.close()
- color(colors.white)
- print("Created "..a)
- end
- end
- end
- color(colors.white)
- if #args < 1 or #args > 2 or args[1] == "help" then
- print("Usages:")
- print("pass lock")
- print("pass edit [user:pass]")
- print("pass SafeMode (To toggle safemode)")
- return
- end
- f = fs.open("/password/safemode","r")
- firstLine = f.readLine()
- f.close()
- if firstLine == "true" then
- safeMode = true
- elseif firstLine == "false" then
- safeMode = false
- else
- print("The safemode file isn't true or false!")
- f = fs.open("/password/safemode","w")
- f.write("true")
- f.close()
- print("Fixed")
- color(colors.yellow)
- print("Please retry your operation...")
- return
- end
- refreshLogin()
- if cUser == nil or cUser == "" or cPass == nil or cPass == "" then
- print("Login file is blank")
- print("Fixing...")
- f = fs.open("/password/login","w")
- f.write("new\nnew")
- f.close()
- print("Success")
- color(colors.yellow)
- print("Please retry your operation...")
- return
- end
- if args[1] == "lock" then --Lock the computer
- clear()
- color(colors.yellow)
- printC("HPWebcamAble's",1)
- printC("Password Program",2)
- cp(1,3)
- print(" ")
- color(colors.blue)
- if safeMode then
- print("SafeMode is on, so you can bypass the login by holding Ctrl+t. Type 'pass SafeMode' in the console to disable it.")
- else
- print("Note: SafeMode is off")
- end
- print(" ")
- color(colors.white)
- print("Current Username:"..cUser)
- print("Current Password:"..cPass)
- print(" ")
- print("Enter - Continue (Lock)")
- print("Tab - Cancel")
- while true do
- event,key = os.pullEvent("key")
- if key == keys.enter then
- break
- elseif key == keys.tab then
- color(colors.red)
- print("Cancelled")
- return
- end
- end
- state,err = pcall(function() main() end) --Catch errors
- elseif args[1] == "edit" then --Edit login
- if args[2] ~= "user" and args[2] ~= "pass" then
- print("Usages:")
- print("pass edit [user:pass]")
- return
- end
- color(colors.white)
- if args[2] == "pass" then --Change the password
- print("Enter new password:")
- tw("> ")
- repeat
- input = read()
- until input ~= ""
- if input == cPass then
- color(colors.red)
- print("That's the current password")
- else
- f = fs.open("/password/login","w")
- f.write(cUser.."\n"..input)
- f.close()
- refreshLogin()
- color(colors.lime)
- print("Password changed")
- return
- end
- else --Change the username
- print("Enter new username:")
- tw("> ")
- repeat
- input = read()
- until input ~= ""
- if input == cUser then
- color(colors.red)
- print("That's the current username")
- return
- else
- f = fs.open("/password/login","w")
- f.write(input.."\n"..cPass)
- f.close()
- refreshLogin()
- color(colors.lime)
- print("Username changed")
- return
- end
- end
- elseif args[1] == "elock" then --Lock without confirmation
- state,err = pcall(function() main() end) --Catch errors
- elseif string.lower(args[1]) == "safemode" then
- print("SafeMode: "..tostring(safeMode))
- if safeMode then
- color(colors.red)
- print("Turning SafeMode off prevents the login from being bypassed")
- end
- color(colors.white)
- print("Toggle SafeMode?")
- print("Y/N")
- while true do
- event,key = os.pullEvent("key")
- if key == keys.y then
- safeMode = not safeMode
- f = fs.open("/password/safemode","w")
- f.write(tostring(safeMode))
- f.close()
- color(colors.lime)
- print("SafeMode toggled")
- os.pullEvent("char")
- error()
- elseif key ==keys.n then
- color(colors.red)
- print("Cancelled")
- os.pullEvent("char")
- error()
- end
- end
- else
- print("Usages:")
- print("pass lock")
- print("pass SafeMode (To toggle safemode)")
- print("pass edit [user:pass]")
- return
- end
- if err then
- if string.find(err,"Terminated") then
- term.setCursorBlink(false)
- color(colors.white,colors.black)
- clear()
- print("Program terminated")
- shell.run("delete startup") --No need to check for the file; if the program has run, it should be there
- else
- color(colors.red,colors.black)
- clear()
- printC("Error",1)
- cp(1,3)
- color(colors.white)
- print(err)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement