Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- oldpullEvent = os.pullEvent
- os.pullEvent = os.pullEventRaw
- tArgs = { ... }
- if #tArgs > 0 then
- if #tArgs == 3 then
- local fileContents = ""
- file = fs.open(".lockInformation", "r")
- fileContents = file.readAll()
- file.close()
- file = fs.open(".lockInformation", "w")
- file.write(fileContents.."\n"..tArgs[1].."\n"..tArgs[2].."\n"..tArgs[3])
- file.close()
- print("Account '"..tArgs[1].."' added successfully.")
- else
- print("Usage to add a user: ")
- print("<username> <password1> <password2>")
- end
- else
- -- VARS --
- tUsers = {} -- Format { sPassword, sPassword_Backup, sUsername }
- nGuesses = 0
- bNeedsUpdate = false
- screenWidth, screenHeight = term.getSize()
- VERSION = 1.7
- -- END VARS --
- -- Helper Functions --
- local function clear() term.clear(); term.setCursorPos(1, 1) end
- local function printBorder()
- for i=1, screenHeight do
- term.setCursorPos(1, i)
- if i == 1 or i == screenHeight then term.write(string.rep("*", screenWidth))
- else term.write("*"..string.rep(" ", screenWidth-2).."*") end
- end
- end
- local function cPrint(height, string)
- term.setCursorPos(screenWidth/2 - string.len(string)/2, height); term.write(string)
- end
- local function rPrint(height, string)
- term.setCursorPos(screenWidth - string.len(string), height); term.write(string)
- end
- local function limitRead( nLength, cReplaceChar )
- term.setCursorBlink( true )
- nLength = nLength or -1 -- -1 is unlimited
- sReturnString = ""
- xPos, yPos = term.getCursorPos()
- while true do
- event, char = os.pullEvent()
- if nLength ~= -1 and string.len( sReturnString ) >= nLength then term.setCursorBlink( false ); return sReturnString end -- Length check
- if event == "char" then sReturnString = sReturnString .. char
- elseif event == "key" then
- if char == 28 then term.setCursorBlink( false ); return sReturnString -- Enter
- elseif char == 14 then -- Backspace
- term.setCursorPos( xPos, yPos )
- term.write( string.rep( " ", string.len( sReturnString ) ) )
- sReturnString = string.sub( sReturnString, 1, string.len( sReturnString )-1 )
- term.setCursorPos( xPos, yPos )
- if not cReplaceChar then term.write( sReturnString )
- else term.write( string.rep( cReplaceChar, string.len( sReturnString ) ) ) end
- end
- end
- term.setCursorPos( xPos, yPos )
- term.write( string.rep( " ", string.len( sReturnString ) ) )
- term.setCursorPos( xPos, yPos )
- if not cReplaceChar then term.write( sReturnString )
- else term.write( string.rep( cReplaceChar, string.len( sReturnString ) ) ) end
- end
- end
- -- END Helper Functions --
- -- Updating Functions --
- local function loadInformation()
- if not fs.exists(".lockInformation") then return false end
- tUsers = {}
- local file = io.open(".lockInformation", "r")
- local fileSize = 0
- for i in file:lines() do fileSize = fileSize+1 end
- file:close()
- file = fs.open( ".lockInformation", "r" )
- for i=1, (fileSize/3) do
- tUsers[i] = { username = file.readLine(), password1 = file.readLine(), password2 = file.readLine() }
- end
- file.close()
- print( #tUsers )
- return true
- end
- local function loadVersion()
- if not fs.exists(".lockVersion") then
- file = fs.open(".lockVersion", "w")
- file.write(VERSION)
- file.close()
- end
- local file = fs.open(".lockVersion", "r")
- VERSION = tonumber(file.readAll())
- file.close()
- end
- local function update(nNewVer)
- local sCode = "Z3dhDRNq"
- file = fs.open(".lockVersion", "w")
- file.write(nNewVer)
- file.close()
- loadVersion()
- clear()
- printBorder()
- cPrint(6, "+-------------+")
- cPrint(7, "| Updating... |")
- cPrint(8, "+-------------+")
- while true do
- local response = http.get(
- "http://pastebin.com/raw.php?i="..textutils.urlEncode( sCode )
- )
- if response then
- local sResponse = response.readAll()
- response.close()
- file = fs.open("/startup", "w")
- file.write(sResponse)
- file.close()
- return
- else return end
- end
- end
- local function checkForUpdate()
- local sCode = "uuBj6zdk"
- clear()
- printBorder()
- cPrint(6, "+---------------------+")
- cPrint(7, "| Checking Version... |")
- cPrint(8, "+---------------------+")
- while true do
- local response = http.get(
- "http://pastebin.com/raw.php?i="..textutils.urlEncode( sCode )
- )
- if response then
- local sResponse = response.readAll()
- response.close()
- if VERSION < tonumber(sResponse) then return tonumber(sResponse), true
- else return false end
- else return false end
- end
- end
- -- END Updating Functions --
- -- User Input Functions --
- local function getNewUserInfo()
- clear()
- printBorder()
- cPrint(3, "+----------+")
- cPrint(4, "| New User |")
- cPrint(5, "+----------+")
- cPrint(7, "Username: ")
- cPrint(8, "Password1: ")
- cPrint(9, "Password2: ")
- term.setCursorPos(screenWidth/2 - string.len("Password1: ")/2 - 8, 11); term.write("Confirm Password1: ") -- -8 to place the ':' so it is lined up with the above.
- term.setCursorPos(screenWidth/2 - string.len("Password1: ")/2 - 8, 12); term.write("Confirm Password2: ")
- term.setCursorPos(screenWidth/2 - string.len("Username: ")/2 + string.len("Username: "), 7)
- local temp_Username = limitRead(12)
- term.setCursorPos(screenWidth/2 - string.len("Password1: ")/2 + string.len("Password1: "), 8)
- local temp_Password1 = limitRead(12, "*")
- term.setCursorPos(screenWidth/2 - string.len("Password2: ")/2 + string.len("Password2: "), 9)
- local temp_Password2 = limitRead(12, "*")
- term.setCursorPos(screenWidth/2 - string.len("Password1: ")/2 + string.len("Password1: "), 11)
- local confirm_Password1 = limitRead(12, "*")
- term.setCursorPos(screenWidth/2 - string.len("Password2: ")/2 + string.len("Password2: "), 12)
- local confirm_Password2 = limitRead(12, "*")
- while true do
- if confirm_Password1 == temp_Password1 and confirm_Password2 == temp_Password2 then
- local file = fs.open(".lockInformation", "w")
- file.writeLine(temp_Username)
- file.writeLine(temp_Password1)
- file.writeLine(temp_Password2)
- file.close()
- return
- else
- term.setCursorPos(screenWidth/2 - string.len("Password1: ")/2 + string.len("Password1: "), 8)
- term.write(string.rep(" ", string.len(temp_Password1)))
- term.setCursorPos(screenWidth/2 - string.len("Password2: ")/2 + string.len("Password2: "), 9)
- term.write(string.rep(" ", string.len(temp_Password2)))
- term.setCursorPos(screenWidth/2 - string.len("Password1: ")/2 + string.len("Password1: "), 11)
- term.write(string.rep(" ", string.len(confirm_Password1)))
- term.setCursorPos(screenWidth/2 - string.len("Password2: ")/2 + string.len("Password2: "), 12)
- term.write(string.rep(" ", string.len(confirm_Password2)))
- term.setCursorPos(screenWidth/2 - string.len("Password1: ")/2 + string.len("Password1: "), 8)
- temp_Password1 = limitRead(12, "*")
- term.setCursorPos(screenWidth/2 - string.len("Password2: ")/2 + string.len("Password2: "), 9)
- temp_Password2 = limitRead(12, "*")
- term.setCursorPos(screenWidth/2 - string.len("Password1: ")/2 + string.len("Password1: "), 11)
- confirm_Password1 = limitRead(12, "*")
- term.setCursorPos(screenWidth/2 - string.len("Password2: ")/2 + string.len("Password2: "), 12)
- confirm_Password2 = limitRead(12, "*")
- end
- end
- end
- local function determineUser() -- Basically login
- if loadInformation() then
- clear()
- printBorder()
- cPrint(4, "+-------------------------+")
- cPrint(5, "| Identification Required |")
- cPrint(6, "+-------------------------+")
- rPrint(screenHeight - 1, "Tries: "..nGuesses.."/5")
- term.setCursorPos(2, screenHeight - 1); term.write("Version: "..VERSION)
- cPrint(7, "Username: ")
- cPrint(8, "Password1: ")
- cPrint(9, "Password2: ")
- term.setCursorPos(screenWidth/2 - string.len("Username: ")/2 + string.len("Username: "), 7)
- local temp_Username = limitRead(12)
- term.setCursorPos(screenWidth/2 - string.len("Password1: ")/2 + string.len("Password1: "), 8)
- local temp_Password1 = limitRead(12, "*")
- term.setCursorPos(screenWidth/2 - string.len("Password2: ")/2 + string.len("Password2: "), 9)
- local temp_Password2 = limitRead(12, "*")
- for i=1, #tUsers do
- if temp_Username == tUsers[i].username then
- if temp_Password1 == tUsers[i].password1 and temp_Password2 == tUsers[i].password2 then return true
- else return false end
- end
- end
- else
- getNewUserInfo()
- cPrint(13, "+-----------------------+")
- cPrint(14, "| Information Saved. |")
- cPrint(15, "| Rebooting to login. |")
- cPrint(16, "+-----------------------+")
- sleep(2)
- os.reboot()
- end
- end
- -- END User Input Functions --
- loadVersion()
- nNewVersion, bNeedsUpdate = checkForUpdate()
- if bNeedsUpdate then update(nNewVersion); shell.run("startup") end
- while true do
- if nGuesses == 5 then os.shutdown() end
- if determineUser() then clear(); print(os.version()); break
- else
- cPrint(11, "+-----------------+")
- cPrint(12, "| Incorrect Input |")
- cPrint(13, "+-----------------+")
- sleep(2)
- nGuesses = nGuesses+1
- end
- end
- end -- Ends the arguments 'else' statement.
- os.pullEvent = oldpullEvent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement