Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Initialize user data
- local users = {
- admin = { role = "admin", password = "admin123" },
- root = { role = "root", password = "rootpass" },
- limited = { role = "limited", password = "limitedpass" }
- }
- -- Current user (initialize as guest)
- local currentUser = { role = "guest" }
- -- Function to log in
- function login(username, password)
- local user = users[username]
- if user and user.password == password then
- currentUser = user
- print("Login successful. Welcome, " .. username .. "!")
- else
- print("Login failed. Incorrect username or password.")
- end
- end
- -- Example usage
- login("limited", "limitedpass")
- -- Function to execute commands based on user role
- function executeCommand(command)
- if currentUser.role == "admin" then
- -- Execute admin commands
- if command == "shutdown" then
- print("System shutting down...")
- elseif command == "reboot" then
- print("System rebooting...")
- else
- print("Unknown command for admin.")
- end
- elseif currentUser.role == "root" then
- -- Execute root commands
- if command == "access_files" then
- print("Accessing system files...")
- else
- print("Unknown command for root.")
- end
- elseif currentUser.role == "limited" then
- -- Execute limited user commands
- if command == "user_program" then
- print("Running user program...")
- elseif command == "delete_file" then
- print("Limited user cannot delete files.")
- else
- print("Unknown command for limited user.")
- end
- else
- print("Guests have limited access.")
- end
- end
- -- Example command execution
- executeCommand("shutdown")
- executeCommand("access_files")
- executeCommand("user_program")
- executeCommand("delete_file")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement