When running WordPress on a testing environment( localhost), I use generic usernames and passwords which are easy to remember.
Unfortutely, sometimes, I choose more difficult p@$$w0rd5 which I inevitable forget. After multiple failed attempts to remember whether I used two or three dollar signs, and in what order, it is time to give-up and reset the password.
Although using wordpress’ “Lost your password” feature will work in most cases, there are times when you may be working offline, or do not have access to your email.
My preferred fix in this situation is, to write the text contents of the reset email to a file. This avoids any need to manually edit hashed password values in the database.
Outputting reset info to a text file can be accomplished with the addition of a single line to the login file ( default login file name is “wp-login.php” ).
Open the login file and locate the “retrieve_password()” function.
Within the function find the last line of text that is appended to “$message”, and insert this code immediately after it:
Your login file should resemble the image above
Using your web browser, open the word-press login page, click the “Lost your password” link, and enter your user name when asked. The reset email should now be saved in your web root directory
Using your system file browser, check inside the website root folder. If the reset was successful you should find the ‘reset_link.txt’ file there. It should contain text which looks something like …
Someone has requested a password reset for the following account: Site Name: Username: usernm If this was a mistake, just ignore this email and nothing will happen. To reset your password, visit the following address: https://localhost/wpsandbox/wp-login.php?action=rp&key=P4BnFkn2XgAbKLk6Vap1&login=usernm
Copy and paste the reset address in your browser url bar to reset the password.
If you chose to save the reset_email.txt file to a different location then apache will need write access to the directory.
If you are familiar with using a line-by-line debugger, you could also set a breakpoint immediately after the url has been appended to the “$message” variable and copy the url value from your debugger watch window.