Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define helper functions for each action
- local function changePassword(username)
- print("Enter new password:")
- local newPassword = io.read()
- local passwordFile = "/disk/users/" .. username .. "/password.txt"
- local file = io.open(passwordFile, "w")
- if file then
- file:write(newPassword)
- file:close()
- print("Password changed successfully.")
- else
- print("Error: Could not open password file.")
- end
- end
- local function changeUsername(currentUsername)
- print("Enter new username:")
- local newUsername = io.read()
- local oldDir = "/disk/users/" .. currentUsername
- local newDir = "/disk/users/" .. newUsername
- -- Rename the directory
- os.rename(oldDir, newDir)
- print("Username changed successfully.")
- end
- local function removePassword(username)
- local passwordFile = "/disk/users/" .. username .. "/password.txt"
- local file = io.open(passwordFile, "w")
- if file then
- file:write("")
- file:close()
- print("Password removed successfully.")
- else
- print("Error: Could not open password file.")
- end
- end
- local function securityCardLogin()
- os.execute("/disk/os/sclogin.lua")
- end
- local function deleteUser(username)
- print("Enter password to confirm user deletion:")
- local enteredPassword = io.read()
- local passwordFile = "/disk/users/" .. username .. "/password.txt"
- local file = io.open(passwordFile, "r")
- if file then
- local correctPassword = file:read()
- file:close()
- if enteredPassword == correctPassword then
- print("Are you sure you want to delete user '" .. username .. "'? (y/n)")
- local confirmation = io.read()
- if confirmation == "y" then
- -- Delete the user's directory and its contents
- local userDir = "/disk/users/" .. username
- os.remove(userDir)
- print("User '" .. username .. "' deleted successfully.")
- else
- print("User deletion cancelled.")
- end
- else
- print("Incorrect password.")
- end
- else
- print("Error: Could not open password file.")
- end
- end
- -- Main program logic
- local function main()
- -- Get the current username from the .currentusr file
- local currentUsrFile = io.open(".currentusr", "r")
- local currentUsername = ""
- if currentUsrFile then
- currentUsername = currentUsrFile:read()
- currentUsrFile:close()
- else
- print("Error: Could not open .currentusr file.")
- return
- end
- print("Welcome, " .. currentUsername)
- print("1. Change password")
- print("2. Change username")
- print("3. Remove password")
- print("4. Security card login")
- print("5. Delete user")
- print("Enter the number of the action you want to perform:")
- local choice = tonumber(io.read())
- if choice == 1 then
- changePassword(currentUsername)
- elseif choice == 2 then
- changeUsername(currentUsername)
- elseif choice == 3 then
- removePassword(currentUsername)
- elseif choice == 4 then
- securityCardLogin()
- elseif choice == 5 then
- deleteUser(currentUsername)
- else
- print("Invalid choice.")
- end
- end
- -- Run the main function
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement