Advertisement
DOGGYWOOF

test2

Jan 21st, 2024
5
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. -- Function to create a new user
  2. function createUser()
  3. ensureLocalUsersDirectory()
  4.  
  5. term.clear()
  6. term.setCursorPos(1, 1)
  7. print("Enter new username:")
  8. local username = read()
  9.  
  10. -- Check if the username already exists
  11. if fs.exists("/disk/users/" .. username) or fs.exists("/local/users/" .. username) then
  12. print("Username already exists. Try again.")
  13. sleep(2)
  14. return
  15. end
  16.  
  17. -- Choose the directory for the new user
  18. print("Choose user directory:")
  19. print("1. /disk/users/")
  20. print("2. /local/users/")
  21.  
  22. local userDirectoryChoice = read()
  23. local userDirectory
  24.  
  25. if userDirectoryChoice == "1" then
  26. userDirectory = "/disk/users/"
  27. elseif userDirectoryChoice == "2" then
  28. userDirectory = "/local/users/"
  29. else
  30. print("Invalid choice. Defaulting to /disk/users/")
  31. userDirectory = "/disk/users/"
  32. end
  33.  
  34. -- Create a directory for the new user
  35. fs.makeDir(userDirectory .. username)
  36.  
  37. -- Ask if a password is required
  38. print("Is a password required for this user? (y/n)")
  39. local passwordRequired = read()
  40. local passwordFile = userDirectory .. username .. "/password.txt"
  41.  
  42. if passwordRequired:lower() == "y" then
  43. -- Prompt for password
  44. local password
  45. repeat
  46. term.clear()
  47. term.setCursorPos(1, 1)
  48. print("Enter password:")
  49. password = read("*")
  50.  
  51. print("Confirm password:")
  52. local confirmPassword = read("*")
  53.  
  54. if password ~= confirmPassword then
  55. print("Passwords do not match. Try again.")
  56. sleep(2)
  57. end
  58. until password == confirmPassword
  59.  
  60. -- Store the password in a text file
  61. local file = fs.open(passwordFile, "w")
  62. file.write(password)
  63. file.close()
  64.  
  65. print("User created successfully.")
  66. else
  67. -- Create bypass.txt file
  68. local bypassFile = userDirectory .. username .. "/bypass.txt"
  69. local file = fs.open(bypassFile, "w")
  70. file.close()
  71.  
  72. print("User created successfully (password bypassed).")
  73. end
  74.  
  75. sleep(2)
  76. end
  77.  
  78. -- Main program
  79. while true do
  80. term.clear()
  81. term.setCursorPos(1, 1)
  82. print("1. Create User")
  83. print("2. Delete User")
  84. print("3. View All Users")
  85. print("4. Password Recovery (Admin Only)")
  86. print("5. Exit")
  87.  
  88. local choice = read()
  89.  
  90. if choice == "1" then
  91. createUser()
  92. elseif choice == "2" then
  93. deleteUser()
  94. elseif choice == "3" then
  95. viewAllUsers()
  96. elseif choice == "4" then
  97. passwordRecovery()
  98. elseif choice == "5" then
  99. exitProgram()
  100. else
  101. print("Invalid choice. Try again.")
  102. sleep(2)
  103. end
  104. end
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement