Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Configuration
- local USERS_FOLDER = "/disk/users/"
- local MAX_ATTEMPTS = 3
- -- Function to read the recovery file for the user
- local function getRecoveryDetails(username)
- local recoveryFile = fs.combine(USERS_FOLDER .. username, "recovery.txt")
- if fs.exists(recoveryFile) then
- local file = fs.open(recoveryFile, "r")
- local recoveryDetails = file.readAll()
- file.close()
- return recoveryDetails
- else
- return nil
- end
- end
- -- Function to handle password reset
- local function resetPassword(username)
- local recoveryDetails = getRecoveryDetails(username)
- if recoveryDetails then
- -- Extract question and answer from the recovery file
- local question, answer = string.match(recoveryDetails, "(.*)=(.*)")
- -- Ask the user the security question
- drawPopupWindow("Password Recovery", {"Security Question: " .. question, "Enter your answer:"})
- local answerEntered = read()
- -- Check if the answer is correct
- if answerEntered == answer then
- -- Prompt for a new password
- drawPopupWindow("Password Recovery", {"Answer correct! Please enter your new password:"})
- local newPassword = read("*")
- -- Save the new password
- local passwordFile = fs.combine(USERS_FOLDER .. username, "password.txt")
- local file = fs.open(passwordFile, "w")
- file.write(newPassword)
- file.close()
- -- Notify the user
- drawPopupWindow("Password Reset", {"Your password has been successfully reset!"})
- os.sleep(2)
- return true
- else
- drawPopupWindow("Password Recovery Failed", {"Incorrect answer to the recovery question!"})
- os.sleep(2)
- return false
- end
- else
- drawPopupWindow("Password Recovery", {"No recovery options available for this account."})
- os.sleep(2)
- return false
- end
- end
- -- Main function to run the password recovery process
- local function initiatePasswordRecovery()
- -- Ask for the username
- drawPopupWindow("Password Recovery", {"Enter your username:"})
- local username = read()
- -- Check if the user exists
- local userFolder = fs.combine(USERS_FOLDER, username)
- if fs.exists(userFolder) then
- -- Attempt password reset
- local success = resetPassword(username)
- if success then
- return
- else
- drawPopupWindow("Password Recovery", {"Password recovery failed."})
- end
- else
- drawPopupWindow("Password Recovery", {"User not found."})
- end
- os.sleep(2)
- end
- -- Start the recovery process
- initiatePasswordRecovery()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement