Ember_Celica

Login Script

Oct 9th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.pullEvent = os.pullEventRaw
  2. function ReadFile(ReadPath)
  3. file = fs.open(ReadPath,'r')
  4. filedata = textutils.unserialize(file.readAll())
  5. file.close()
  6. return filedata
  7. end
  8. local function FileWrite(WritePath, DataKey, DataValue)
  9. local FileContents = ReadFile(WritePath)
  10. local file = fs.open(WritePath, 'w')
  11. FileContents[DataKey] = DataValue
  12. file.write(textutils.serialize(FileContents))
  13. file.close()
  14. end
  15. local function WaitForKey()
  16. write("Please press any key to continue"..'\n')
  17. local event, WaitKey = os.pullEvent('key')
  18. end
  19. local UserDataPath = "UserData.config"
  20. local UserRankPath = "UserRank.config"
  21. local RankDefault = "User"
  22. local rank = nil
  23.  
  24. local UserCredentials = ReadFile(UserDataPath)
  25. local UserRanks = ReadFile(UserRankPath)
  26. write("Config Loaded"..'\n')
  27. write("Welcome to the Login Screen!"..'\n')
  28. write("Username: ")
  29. user = read()
  30. write("Password: ")
  31. pass = read('*')
  32.  
  33. write("Validating Credentials..."..'\n')
  34. for username,password in pairs(UserCredentials) do
  35.   if user == username and pass == password then
  36.   success = true
  37.   rank = UserRanks[username]
  38.   if rank == nil then
  39.   rank = RankDefault
  40.   write("No rank found for user: "..username.." in the database, assigning default rank"..'\n')
  41.   FileWrite(UserRankPath,username,RankDefault)
  42.   end
  43.   break
  44.   else
  45.   success = false
  46.   end
  47. end
  48.  
  49. if success == true then
  50. write("Your Credentials Were Valid, Welcome "..user.."."..'\n')
  51. shell.run("clear")
  52. write("Currently Logged in: "..user..'\n'.."System Rank: "..rank..'\n')
  53. access = true
  54. WaitForKey()
  55. else
  56. write("Your Credentials Were Invalid, Please Try Again"..'\n')
  57. sleep(3)
  58. os.reboot()
  59. end
  60. if access == true and rank == "Admin" then
  61.   while true do
  62.   shell.run("clear")
  63.   write("Possible Command options (Use NumPad Keys): "..'\n')
  64.   write("1 - View all registered users"..'\n')
  65.   write("2 - Add a user/Change user password"..'\n')
  66.   write("3 - Delete a user"..'\n')
  67.   write("4 - Change a user rank/Add user rank"..'\n')
  68.   write("5 - Reboot the system"..'\n')
  69.   write("6 - View logged in user"..'\n')
  70.   local event, key = os.pullEvent('key')
  71.     if key == keys.numPad1 then
  72.       local UserList = ReadFile(UserDataPath)
  73.       for username,password in pairs(UserList) do
  74.       write(username..'\n')
  75.       end
  76.       WaitForKey()
  77.     elseif key == keys.numPad2 then
  78.       write("What is their username: ")
  79.       NewUser = read()
  80.       write("What is their password: ")
  81.       NewPass = read()
  82.       write("Attempting to add user: "..NewUser.." with the password of: "..NewPass.."."..'\n'.."Are you sure?[Y/N]")
  83.       local event, key = os.pullEvent('key')
  84.       if key == keys.y then
  85.       FileWrite(UserDataPath,NewUser,NewPass)
  86.       else
  87.       write("Did not add user because the Y key was not pressed."..'\n')
  88.       end
  89.     elseif key == keys.numPad3 then
  90.       write("What is their username: ")
  91.       DelUser = read()
  92.       write("Attempting to delete user: "..DelUser..'\n'.."Are you sure?[Y/N]")
  93.       local event, key = os.pullEvent('key')
  94.       if key == keys.y then
  95.       FileWrite(UserDataPath,DelUser,nil)
  96.       else
  97.       write("Did not delete user because the Y key was not pressed."..'\n')
  98.       end
  99.     elseif key == keys.numPad4 then
  100.       write("What is their username: ")
  101.       RankUsername = read()
  102.       write("What rank do you want to assign: ")
  103.       NewRank = read()
  104.       write("Attempting to add rank to user: "..RankUsername.." with rank: "..NewRank.."."..'\n'.."Are you sure?[Y/N]")
  105.       local event, key = os.pullEvent('key')
  106.       if key == keys.y then
  107.       FileWrite(UserRankPath,RankUsername,NewRank)
  108.       else
  109.       write("Did not change user rank because the Y key was not pressed."..'\n')
  110.       end
  111.     elseif key == keys.numPad5 then
  112.       for i=3,1,-1 do
  113.       write("Rebooting the system in "..i.." seconds"..'\n')
  114.       sleep(1)
  115.       end
  116.       os.reboot()
  117.     elseif key == keys.numPad6 then
  118.       write("Current User: "..user..'\n')
  119.       WaitForKey()
  120.     else
  121.       write("There has seemed to be an issue with key"..'\n'.."processing, did you use numpad?")
  122.     end
  123.   end
  124. elseif access == true and rank == "User" then
  125.   while true do
  126.   shell.run("clear")
  127.   write("Possible Command Options (please use NumPad Keys: "..'\n')
  128.   write("1 - Change Password"..'\n')
  129.   write("2 - View Logged In User"..'\n')
  130.   write("3 - Reboot System"..'\n')
  131.   local event, key = os.pullEvent('key')
  132.   if key == keys.numPad1 then
  133.   write("Confirm Current Password Please: ")
  134.   ConfPass = read('*')
  135.     for username,password in pairs(UserCredentials) do
  136.       if username == user and ConfPass == password then
  137.       write("Password Confirmed. New password: ")
  138.       NewPass = read('*')
  139.       write("Confirm New Password: ")
  140.       NewPassConf = read('*')
  141.         if NewPass == NewPassConf then
  142.         FileWrite(UserDataPath,username,NewPass)
  143.         end
  144.       end
  145.     end
  146.   elseif key == keys.numPad2 then
  147.   write("Current User: "..user)
  148.   WaitForKey()
  149.   elseif key == keys.numPad3 then
  150.   for i=3,1,-1 do
  151.   write("Restarting in "..i.." seconds"..'\n')
  152.   sleep(1)
  153.   end
  154.   os.reboot()
  155.   else
  156.   write("there is something wrong with the key detector"..'\n'.."did you use NumPad?")
  157.   end
  158.   end
  159. else
  160. write("You do not have a System Rank yet, contact System Admin")
  161. WaitForKey()
  162. os.reboot()
  163. end
Add Comment
Please, Sign In to add comment