Advertisement
DOGGYWOOF

Untitled

Feb 21st, 2025 (edited)
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. -- Define helper functions for each action
  2. local function changePassword(username)
  3. print("Enter new password:")
  4. local newPassword = io.read()
  5. local passwordFile = "/disk/users/" .. username .. "/password.txt"
  6. local file = io.open(passwordFile, "w")
  7. if file then
  8. file:write(newPassword)
  9. file:close()
  10. print("Password changed successfully.")
  11. else
  12. print("Error: Could not open password file.")
  13. end
  14. end
  15.  
  16. local function changeUsername(currentUsername)
  17. print("Enter new username:")
  18. local newUsername = io.read()
  19. local oldDir = "/disk/users/" .. currentUsername
  20. local newDir = "/disk/users/" .. newUsername
  21.  
  22. -- Rename the directory
  23. os.rename(oldDir, newDir)
  24. print("Username changed successfully.")
  25. end
  26.  
  27. local function removePassword(username)
  28. local passwordFile = "/disk/users/" .. username .. "/password.txt"
  29. local file = io.open(passwordFile, "w")
  30. if file then
  31. file:write("")
  32. file:close()
  33. print("Password removed successfully.")
  34. else
  35. print("Error: Could not open password file.")
  36. end
  37. end
  38.  
  39. local function securityCardLogin()
  40. os.execute("/disk/os/sclogin.lua")
  41. end
  42.  
  43. local function deleteUser(username)
  44. print("Enter password to confirm user deletion:")
  45. local enteredPassword = io.read()
  46. local passwordFile = "/disk/users/" .. username .. "/password.txt"
  47. local file = io.open(passwordFile, "r")
  48.  
  49. if file then
  50. local correctPassword = file:read()
  51. file:close()
  52.  
  53. if enteredPassword == correctPassword then
  54. print("Are you sure you want to delete user '" .. username .. "'? (y/n)")
  55. local confirmation = io.read()
  56.  
  57. if confirmation == "y" then
  58. -- Delete the user's directory and its contents
  59. local userDir = "/disk/users/" .. username
  60. os.remove(userDir)
  61. print("User '" .. username .. "' deleted successfully.")
  62. else
  63. print("User deletion cancelled.")
  64. end
  65. else
  66. print("Incorrect password.")
  67. end
  68. else
  69. print("Error: Could not open password file.")
  70. end
  71. end
  72.  
  73. -- Main program logic
  74. local function main()
  75. -- Get the current username from the .currentusr file
  76. local currentUsrFile = io.open(".currentusr", "r")
  77. local currentUsername = ""
  78. if currentUsrFile then
  79. currentUsername = currentUsrFile:read()
  80. currentUsrFile:close()
  81. else
  82. print("Error: Could not open .currentusr file.")
  83. return
  84. end
  85.  
  86. print("Welcome, " .. currentUsername)
  87. print("1. Change password")
  88. print("2. Change username")
  89. print("3. Remove password")
  90. print("4. Security card login")
  91. print("5. Delete user")
  92. print("Enter the number of the action you want to perform:")
  93.  
  94. local choice = tonumber(io.read())
  95.  
  96. if choice == 1 then
  97. changePassword(currentUsername)
  98. elseif choice == 2 then
  99. changeUsername(currentUsername)
  100. elseif choice == 3 then
  101. removePassword(currentUsername)
  102. elseif choice == 4 then
  103. securityCardLogin()
  104. elseif choice == 5 then
  105. deleteUser(currentUsername)
  106. else
  107. print("Invalid choice.")
  108. end
  109. end
  110.  
  111. -- Run the main function
  112. main()
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement