Advertisement
DOGGYWOOF

test

Jan 21st, 2024
4
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. -- Initialize user data
  2. local users = {
  3. admin = { role = "admin", password = "admin123" },
  4. root = { role = "root", password = "rootpass" },
  5. limited = { role = "limited", password = "limitedpass" }
  6. }
  7.  
  8. -- Current user (initialize as guest)
  9. local currentUser = { role = "guest" }
  10.  
  11. -- Function to log in
  12. function login(username, password)
  13. local user = users[username]
  14. if user and user.password == password then
  15. currentUser = user
  16. print("Login successful. Welcome, " .. username .. "!")
  17. else
  18. print("Login failed. Incorrect username or password.")
  19. end
  20. end
  21.  
  22. -- Example usage
  23. login("limited", "limitedpass")
  24.  
  25. -- Function to execute commands based on user role
  26. function executeCommand(command)
  27. if currentUser.role == "admin" then
  28. -- Execute admin commands
  29. if command == "shutdown" then
  30. print("System shutting down...")
  31. elseif command == "reboot" then
  32. print("System rebooting...")
  33. else
  34. print("Unknown command for admin.")
  35. end
  36. elseif currentUser.role == "root" then
  37. -- Execute root commands
  38. if command == "access_files" then
  39. print("Accessing system files...")
  40. else
  41. print("Unknown command for root.")
  42. end
  43. elseif currentUser.role == "limited" then
  44. -- Execute limited user commands
  45. if command == "user_program" then
  46. print("Running user program...")
  47. elseif command == "delete_file" then
  48. print("Limited user cannot delete files.")
  49. else
  50. print("Unknown command for limited user.")
  51. end
  52. else
  53. print("Guests have limited access.")
  54. end
  55. end
  56.  
  57. -- Example command execution
  58. executeCommand("shutdown")
  59. executeCommand("access_files")
  60. executeCommand("user_program")
  61. executeCommand("delete_file")
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement