Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Project info:
- Name: jLogin
- Creator: Jesusthekiller
- Language: Lua (CC)
- Website: None
- License: GNU GPL
- License file can be fount at www.jesusthekiller.com/license-gpl.html
- Version: 1.0
- ]]--
- --[[
- Changelog:
- 1.0:
- Initial Release
- ]]--
- --[[
- LICENSE:
- jLogin
- Copyright (c) 2013 Jesusthekiller
- This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
- ]]--
- -- Prevent CTRL+T
- local oev = os.pullEvent
- os.pullEvent = os.pullEventRaw
- -- Get sha256 API
- if not fs.exists("sha256") then
- assert(http, "HTTP API required to download dependencies!")
- shell.run("pastebin", "get", "8K9hVgXV", "sha256")
- end
- if not sha256 then
- os.loadAPI("sha256")
- end
- -- Create command
- if not fs.isDir("login") then -- Remove if not dir
- fs.delete("login")
- end
- if not fs.exists("login") then -- Create dir
- fs.makeDir("login")
- end
- if not fs.exists("login/login") then -- Download login cmd
- assert(http, "HTTP API required to download dependencies!")
- shell.run("pastebin", "get", "pRan4MNW", "login/login")
- end
- shell.setPath("/login:"..shell.path()) -- Set path
- -- Login screen
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- if not fs.exists("login_users") then -- Check for file
- print("No users added! Do login adduser <login> <password>")
- return
- end
- local f = fs.open("login_users", "r") or os.reboot() -- Open users file
- local t = {}
- for token in string.gmatch(f.readAll(), "[^\n]+") do -- Users file to table
- table.insert(t, token)
- end
- f.close()
- if #t < 2 or #t % 2 == 1 then -- Check for corrupted file
- fs.delete("login_users")
- print("login_users file is empty or corrupted! File deleted!")
- print("Press any key...")
- coroutine.yield()
- os.pullEvent("key")
- os.reboot()
- end
- local counter = 0
- while true do -- Login loop
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- if counter % 3 == 0 and counter ~= 0 then -- 30s sleep every 3 fails
- print("Exceeded maximum fail count! You have failed "..counter.." times!")
- for i = counter * 5, 1, -1 do
- term.setCursorPos(1, 3)
- term.clearLine()
- write("You have to wait "..i..((i == 1) and " second" or " seconds"))
- sleep(1)
- end
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- end
- if counter == 0 then
- print("This computer is locked!")
- end
- write("Login: ")
- local login = read():gsub("%s", "") -- Remove white chars
- write("Password: ")
- local password = read(" ") -- Read w/o any characters shown
- local logged
- for i = 1, #t, 2 do -- Check pass
- if t[i]:lower() == login:lower() then
- if t[i+1] == sha256.sha256(password) then
- logged = true
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- print("Welcome, "..login)
- break
- end
- end
- end
- if logged then
- break
- else
- print("Wrong login and password combo!")
- sleep(1) -- For no brute force
- counter = counter + 1
- end
- end
- -- Unload APIs
- os.unloadAPI("sha256")
- -- Restore os.pullEvent
- os.pullEvent = oev
Advertisement
Add Comment
Please, Sign In to add comment