Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to create a new user
- function createUser()
- 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) then
- print("Username already exists. Try again.")
- sleep(2)
- return
- end
- -- Create a directory for the new user
- fs.makeDir("/disk/users/" .. username)
- -- 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("/disk/users/" .. username .. "/password.txt", "w")
- file.write(password)
- file.close()
- print("User created successfully.")
- sleep(2)
- end
- -- Function to delete a user
- function deleteUser()
- term.clear()
- term.setCursorPos(1, 1)
- print("Enter username to delete:")
- local username = read()
- -- Check if the username exists
- if not fs.exists("/disk/users/" .. username) then
- print("User not found. Try again.")
- sleep(2)
- return
- end
- -- Prompt for password to confirm deletion
- print("Enter password to confirm deletion:")
- local inputPassword = read("*")
- -- Read stored password from the file
- local file = fs.open("/disk/users/" .. username .. "/password.txt", "r")
- local storedPassword = file.readAll()
- file.close()
- -- Compare entered password with stored password
- if inputPassword == storedPassword then
- -- Delete the user directory
- fs.delete("/disk/users/" .. username)
- print("User deleted successfully.")
- else
- print("Incorrect password. Deletion failed.")
- end
- sleep(2)
- end
- -- Function to exit and run /disk/os/gui
- function exitProgram()
- term.clear()
- term.setCursorPos(1, 1)
- print("Exiting program...")
- sleep(1)
- shell.run("/disk/os/gui")
- error("Exiting program.")
- end
- -- Main program
- while true do
- term.clear()
- term.setCursorPos(1, 1)
- print("1. Create User")
- print("2. Delete User")
- print("3. Exit")
- local choice = read()
- if choice == "1" then
- createUser()
- elseif choice == "2" then
- deleteUser()
- elseif choice == "3" then
- exitProgram()
- else
- print("Invalid choice. Try again.")
- sleep(2)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement