Advertisement
DOGGYWOOF

Untitled

Jan 20th, 2024
4
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. -- Function to create a new user
  2. function createUser()
  3. term.clear()
  4. term.setCursorPos(1, 1)
  5. print("Enter new username:")
  6. local username = read()
  7.  
  8. -- Check if the username already exists
  9. if fs.exists("/disk/users/" .. username) then
  10. print("Username already exists. Try again.")
  11. sleep(2)
  12. return
  13. end
  14.  
  15. -- Create a directory for the new user
  16. fs.makeDir("/disk/users/" .. username)
  17.  
  18. -- Prompt for password
  19. local password
  20. repeat
  21. term.clear()
  22. term.setCursorPos(1, 1)
  23. print("Enter password:")
  24. password = read("*")
  25.  
  26. print("Confirm password:")
  27. local confirmPassword = read("*")
  28.  
  29. if password ~= confirmPassword then
  30. print("Passwords do not match. Try again.")
  31. sleep(2)
  32. end
  33. until password == confirmPassword
  34.  
  35. -- Store the password in a text file
  36. local file = fs.open("/disk/users/" .. username .. "/password.txt", "w")
  37. file.write(password)
  38. file.close()
  39.  
  40. print("User created successfully.")
  41. sleep(2)
  42. end
  43.  
  44. -- Function to delete a user
  45. function deleteUser()
  46. term.clear()
  47. term.setCursorPos(1, 1)
  48. print("Enter username to delete:")
  49. local username = read()
  50.  
  51. -- Check if the username exists
  52. if not fs.exists("/disk/users/" .. username) then
  53. print("User not found. Try again.")
  54. sleep(2)
  55. return
  56. end
  57.  
  58. -- Prompt for password to confirm deletion
  59. print("Enter password to confirm deletion:")
  60. local inputPassword = read("*")
  61.  
  62. -- Read stored password from the file
  63. local file = fs.open("/disk/users/" .. username .. "/password.txt", "r")
  64. local storedPassword = file.readAll()
  65. file.close()
  66.  
  67. -- Compare entered password with stored password
  68. if inputPassword == storedPassword then
  69. -- Delete the user directory
  70. fs.delete("/disk/users/" .. username)
  71. print("User deleted successfully.")
  72. else
  73. print("Incorrect password. Deletion failed.")
  74. end
  75.  
  76. sleep(2)
  77. end
  78.  
  79. -- Function to exit and run /disk/os/gui
  80. function exitProgram()
  81. term.clear()
  82. term.setCursorPos(1, 1)
  83. print("Exiting program...")
  84. sleep(1)
  85. shell.run("/disk/os/gui")
  86. error("Exiting program.")
  87. end
  88.  
  89. -- Main program
  90. while true do
  91. term.clear()
  92. term.setCursorPos(1, 1)
  93. print("1. Create User")
  94. print("2. Delete User")
  95. print("3. Exit")
  96.  
  97. local choice = read()
  98.  
  99. if choice == "1" then
  100. createUser()
  101. elseif choice == "2" then
  102. deleteUser()
  103. elseif choice == "3" then
  104. exitProgram()
  105. else
  106. print("Invalid choice. Try again.")
  107. sleep(2)
  108. end
  109. end
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement