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/>.
- ]]--
- if not sha256 then
- os.loadAPI("sha256")
- end
- local args = {...}
- local function usage()
- print("Usage:")
- print(" login lock")
- print(" login adduser <login> <password>")
- print(" login deluser <login> <password>")
- print(" login passwd <login> <oldpass> <newpass>")
- return
- end
- if not fs.exists("login_users") then
- local f = fs.open("login_users", "w")
- f.close()
- end
- args[1] = args[1] and args[1]:lower() -- check for no args, lower command
- if args[1] == "lock" then
- shell.run("startup")
- elseif args[1] == "adduser" and args[2] and args[3] then
- local login = args[2]:lower():gsub("%s", "") -- Format user
- local pass = sha256.sha256(args[3]) -- Encode password
- local f = fs.open("login_users", "r") or error("Can not open file login_users! Please reboot!", 0)
- for token in string.gmatch(f.readAll(), "[^\n]+") do -- Check is user does not exist
- local p1, p2 = token:find(login)
- if p1 == 1 and p2 == #token then
- f.close()
- error("User "..login.." exists!", 0)
- end
- end
- f.close()
- -- Add users
- local f = fs.open("login_users", "a") or error("Can not open file login_users! Please reboot!", 0)
- f.writeLine(login)
- f.writeLine(pass)
- f.close()
- print("User "..login.." added!")
- elseif args[1] == "deluser" and args[2] and args[3] then
- local login = args[2]:lower():gsub("%s", "") -- Format user
- local pass = sha256.sha256(args[3]) -- Encode password
- local f = fs.open("login_users", "r") or error("Can not open file login_users! Please reboot!", 0)
- local file = f.readAll()
- f.close()
- if file:find(login.."\n"..pass) == 1 then
- file = file:gsub(login.."\n"..pass, "")
- elseif file:find("\n"..login.."\n"..pass) then
- file = file:gsub("\n"..login.."\n"..pass, "")
- else
- error("Wrong user and password combo!", 0)
- end
- local f = fs.open("login_users", "w") or error("Can not open file login_users! Please reboot!", 0)
- f.write(file)
- f.close()
- print("User "..login.." deleted!")
- elseif args[1] == "passwd" and args[2] and args[3] and args[4] then
- local login = args[2]:lower():gsub("%s", "") -- Format user
- local pass = sha256.sha256(args[3]) -- Encode password
- local npass = sha256.sha256(args[4]) -- Encode password
- local f = fs.open("login_users", "r") or error("Can not open file login_users! Please reboot!", 0)
- local file = f.readAll()
- f.close()
- if file:find(login.."\n"..pass) == 1 then
- file = file:gsub(login.."\n"..pass, login.."\n"..npass)
- elseif file:find("\n"..login.."\n"..pass) then
- file = file:gsub("\n"..login.."\n"..pass, "\n"..login.."\n"..npass)
- else
- error("Wrong user and password combo!", 0)
- end
- local f = fs.open("login_users", "w") or error("Can not open file login_users! Please reboot!", 0)
- f.write(file)
- f.close()
- print("Password for user "..login.." changed!")
- else
- usage()
- end
- os.unloadAPI("sha256")
Advertisement
Add Comment
Please, Sign In to add comment