Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to create a new user
- function createUser()
- ensureLocalUsersDirectory()
- term.clear()
- term.setCursorPos(1, 1)
- print("Enter new username:")
- local username = read()
- -- Check if the username already exists
- if fs.exists("/disk/users/" .. username) or fs.exists("/local/users/" .. username) then
- print("Username already exists. Try again.")
- sleep(2)
- return
- end
- -- Choose the directory for the new user
- print("Choose user directory:")
- print("1. /disk/users/")
- print("2. /local/users/")
- local userDirectoryChoice = read()
- local userDirectory
- if userDirectoryChoice == "1" then
- userDirectory = "/disk/users/"
- elseif userDirectoryChoice == "2" then
- userDirectory = "/local/users/"
- else
- print("Invalid choice. Defaulting to /disk/users/")
- userDirectory = "/disk/users/"
- end
- -- Create a directory for the new user
- fs.makeDir(userDirectory .. username)
- -- Ask if a password is required
- print("Is a password required for this user? (y/n)")
- local passwordRequired = read()
- local passwordFile = userDirectory .. username .. "/password.txt"
- if passwordRequired:lower() == "y" then
- -- Prompt for password
- local password
- repeat
- term.clear()
- term.setCursorPos(1, 1)
- print("Enter password:")
- password = read("*")
- print("Confirm password:")
- local confirmPassword = read("*")
- if password ~= confirmPassword then
- print("Passwords do not match. Try again.")
- sleep(2)
- end
- until password == confirmPassword
- -- Store the password in a text file
- local file = fs.open(passwordFile, "w")
- file.write(password)
- file.close()
- print("User created successfully.")
- else
- -- Create bypass.txt file
- local bypassFile = userDirectory .. username .. "/bypass.txt"
- local file = fs.open(bypassFile, "w")
- file.close()
- print("User created successfully (password bypassed).")
- end
- sleep(2)
- end
- -- Main program
- while true do
- term.clear()
- term.setCursorPos(1, 1)
- print("1. Create User")
- print("2. Delete User")
- print("3. View All Users")
- print("4. Password Recovery (Admin Only)")
- print("5. Exit")
- local choice = read()
- if choice == "1" then
- createUser()
- elseif choice == "2" then
- deleteUser()
- elseif choice == "3" then
- viewAllUsers()
- elseif choice == "4" then
- passwordRecovery()
- elseif choice == "5" then
- exitProgram()
- else
- print("Invalid choice. Try again.")
- sleep(2)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement