Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- function ReadFile(ReadPath)
- file = fs.open(ReadPath,'r')
- filedata = textutils.unserialize(file.readAll())
- file.close()
- return filedata
- end
- local function FileWrite(WritePath, DataKey, DataValue)
- local FileContents = ReadFile(WritePath)
- local file = fs.open(WritePath, 'w')
- FileContents[DataKey] = DataValue
- file.write(textutils.serialize(FileContents))
- file.close()
- end
- local function WaitForKey()
- write("Please press any key to continue"..'\n')
- local event, WaitKey = os.pullEvent('key')
- end
- local UserDataPath = "UserData.config"
- local UserRankPath = "UserRank.config"
- local RankDefault = "User"
- local rank = nil
- local UserCredentials = ReadFile(UserDataPath)
- local UserRanks = ReadFile(UserRankPath)
- write("Config Loaded"..'\n')
- write("Welcome to the Login Screen!"..'\n')
- write("Username: ")
- user = read()
- write("Password: ")
- pass = read('*')
- write("Validating Credentials..."..'\n')
- for username,password in pairs(UserCredentials) do
- if user == username and pass == password then
- success = true
- rank = UserRanks[username]
- if rank == nil then
- rank = RankDefault
- write("No rank found for user: "..username.." in the database, assigning default rank"..'\n')
- FileWrite(UserRankPath,username,RankDefault)
- end
- break
- else
- success = false
- end
- end
- if success == true then
- write("Your Credentials Were Valid, Welcome "..user.."."..'\n')
- shell.run("clear")
- write("Currently Logged in: "..user..'\n'.."System Rank: "..rank..'\n')
- access = true
- WaitForKey()
- else
- write("Your Credentials Were Invalid, Please Try Again"..'\n')
- sleep(3)
- os.reboot()
- end
- if access == true and rank == "Admin" then
- while true do
- shell.run("clear")
- write("Possible Command options (Use NumPad Keys): "..'\n')
- write("1 - View all registered users"..'\n')
- write("2 - Add a user/Change user password"..'\n')
- write("3 - Delete a user"..'\n')
- write("4 - Change a user rank/Add user rank"..'\n')
- write("5 - Reboot the system"..'\n')
- write("6 - View logged in user"..'\n')
- local event, key = os.pullEvent('key')
- if key == keys.numPad1 then
- local UserList = ReadFile(UserDataPath)
- for username,password in pairs(UserList) do
- write(username..'\n')
- end
- WaitForKey()
- elseif key == keys.numPad2 then
- write("What is their username: ")
- NewUser = read()
- write("What is their password: ")
- NewPass = read()
- write("Attempting to add user: "..NewUser.." with the password of: "..NewPass.."."..'\n'.."Are you sure?[Y/N]")
- local event, key = os.pullEvent('key')
- if key == keys.y then
- FileWrite(UserDataPath,NewUser,NewPass)
- else
- write("Did not add user because the Y key was not pressed."..'\n')
- end
- elseif key == keys.numPad3 then
- write("What is their username: ")
- DelUser = read()
- write("Attempting to delete user: "..DelUser..'\n'.."Are you sure?[Y/N]")
- local event, key = os.pullEvent('key')
- if key == keys.y then
- FileWrite(UserDataPath,DelUser,nil)
- else
- write("Did not delete user because the Y key was not pressed."..'\n')
- end
- elseif key == keys.numPad4 then
- write("What is their username: ")
- RankUsername = read()
- write("What rank do you want to assign: ")
- NewRank = read()
- write("Attempting to add rank to user: "..RankUsername.." with rank: "..NewRank.."."..'\n'.."Are you sure?[Y/N]")
- local event, key = os.pullEvent('key')
- if key == keys.y then
- FileWrite(UserRankPath,RankUsername,NewRank)
- else
- write("Did not change user rank because the Y key was not pressed."..'\n')
- end
- elseif key == keys.numPad5 then
- for i=3,1,-1 do
- write("Rebooting the system in "..i.." seconds"..'\n')
- sleep(1)
- end
- os.reboot()
- elseif key == keys.numPad6 then
- write("Current User: "..user..'\n')
- WaitForKey()
- else
- write("There has seemed to be an issue with key"..'\n'.."processing, did you use numpad?")
- end
- end
- elseif access == true and rank == "User" then
- while true do
- shell.run("clear")
- write("Possible Command Options (please use NumPad Keys: "..'\n')
- write("1 - Change Password"..'\n')
- write("2 - View Logged In User"..'\n')
- write("3 - Reboot System"..'\n')
- local event, key = os.pullEvent('key')
- if key == keys.numPad1 then
- write("Confirm Current Password Please: ")
- ConfPass = read('*')
- for username,password in pairs(UserCredentials) do
- if username == user and ConfPass == password then
- write("Password Confirmed. New password: ")
- NewPass = read('*')
- write("Confirm New Password: ")
- NewPassConf = read('*')
- if NewPass == NewPassConf then
- FileWrite(UserDataPath,username,NewPass)
- end
- end
- end
- elseif key == keys.numPad2 then
- write("Current User: "..user)
- WaitForKey()
- elseif key == keys.numPad3 then
- for i=3,1,-1 do
- write("Restarting in "..i.." seconds"..'\n')
- sleep(1)
- end
- os.reboot()
- else
- write("there is something wrong with the key detector"..'\n'.."did you use NumPad?")
- end
- end
- else
- write("You do not have a System Rank yet, contact System Admin")
- WaitForKey()
- os.reboot()
- end
Add Comment
Please, Sign In to add comment