Advertisement
Guest User

NewLogin

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