Advertisement
DOGGYWOOF

Untitled

Feb 20th, 2025
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. -- Configuration
  2. local USERS_FOLDER = "/disk/users/"
  3. local MAX_ATTEMPTS = 3
  4.  
  5. -- Function to read the recovery file for the user
  6. local function getRecoveryDetails(username)
  7. local recoveryFile = fs.combine(USERS_FOLDER .. username, "recovery.txt")
  8. if fs.exists(recoveryFile) then
  9. local file = fs.open(recoveryFile, "r")
  10. local recoveryDetails = file.readAll()
  11. file.close()
  12. return recoveryDetails
  13. else
  14. return nil
  15. end
  16. end
  17.  
  18. -- Function to handle password reset
  19. local function resetPassword(username)
  20. local recoveryDetails = getRecoveryDetails(username)
  21. if recoveryDetails then
  22. -- Extract question and answer from the recovery file
  23. local question, answer = string.match(recoveryDetails, "(.*)=(.*)")
  24.  
  25. -- Ask the user the security question
  26. drawPopupWindow("Password Recovery", {"Security Question: " .. question, "Enter your answer:"})
  27. local answerEntered = read()
  28.  
  29. -- Check if the answer is correct
  30. if answerEntered == answer then
  31. -- Prompt for a new password
  32. drawPopupWindow("Password Recovery", {"Answer correct! Please enter your new password:"})
  33. local newPassword = read("*")
  34.  
  35. -- Save the new password
  36. local passwordFile = fs.combine(USERS_FOLDER .. username, "password.txt")
  37. local file = fs.open(passwordFile, "w")
  38. file.write(newPassword)
  39. file.close()
  40.  
  41. -- Notify the user
  42. drawPopupWindow("Password Reset", {"Your password has been successfully reset!"})
  43. os.sleep(2)
  44. return true
  45. else
  46. drawPopupWindow("Password Recovery Failed", {"Incorrect answer to the recovery question!"})
  47. os.sleep(2)
  48. return false
  49. end
  50. else
  51. drawPopupWindow("Password Recovery", {"No recovery options available for this account."})
  52. os.sleep(2)
  53. return false
  54. end
  55. end
  56.  
  57. -- Main function to run the password recovery process
  58. local function initiatePasswordRecovery()
  59. -- Ask for the username
  60. drawPopupWindow("Password Recovery", {"Enter your username:"})
  61. local username = read()
  62.  
  63. -- Check if the user exists
  64. local userFolder = fs.combine(USERS_FOLDER, username)
  65. if fs.exists(userFolder) then
  66. -- Attempt password reset
  67. local success = resetPassword(username)
  68. if success then
  69. return
  70. else
  71. drawPopupWindow("Password Recovery", {"Password recovery failed."})
  72. end
  73. else
  74. drawPopupWindow("Password Recovery", {"User not found."})
  75. end
  76. os.sleep(2)
  77. end
  78.  
  79. -- Start the recovery process
  80. initiatePasswordRecovery()
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement