What to Do If You Forgot Your WordPress Admin Password
Published February 23, 2024 at 12:13 am
Immediate Steps for Recovering Your WordPress Admin Password
If you have found yourself locked out of your WordPress admin panel, do not worry.
There is a straightforward solution to regain access.
Below is a quick guide on how to reset your password directly through your WordPress database.
TLDR: Quick Password Reset Using phpMyAdmin
To reset your WordPress admin password:
- Log in to your hosting control panel.
- Open the phpMyAdmin tool.
- Select your WordPress database.
- Browse to wp_users table.
- Edit the corresponding user entry.
- Enter a new password.
- In the Function dropdown, select MD5.
- Save the changes.
UPDATE `wp_users` SET `user_pass` = MD5('newpassword') WHERE `user_login` = 'admin';
Replace ‘newpassword’ with your desired password and ‘admin’ with your username.
Resetting Your WordPress Admin Password via Email
If you have access to the email registered with the admin account, this is the simplest method.
On the WordPress login page, click on the “Lost your password?” link.
Enter your email and follow the instructions sent to you.
Changing the Password Through phpMyAdmin
If emails are not being sent or you no longer have access to the admin email, the phpMyAdmin method will help.
Access phpMyAdmin through your hosting panel, locate the ‘wp_users’ table, and edit the ‘user_pass’ field.
Your password must be hashed, so use the MD5 function when updating.
Using FTP to Create a New Admin User
You can also create a new user with admin privileges via FTP.
Edit the theme’s functions.php file, adding a new user with admin role:
function wpb_admin_account(){
$user = 'username';
$pass = 'password';
$email = 'email@example.com';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
}
add_action('init','wpb_admin_account');
Make sure to replace ‘username’, ‘password’, and ’email@example.com’ with your details.
Once logged in, remember to remove this code from functions.php.
Using the Emergency Password Reset Script
Alternatively, you can use the Emergency Password Reset Script provided by WordPress.
You’ll need to create a `.php` file with the script and upload it to the root directory of your WordPress installation.
Once uploaded, running this script allows you to reset the password.
Additional Pro Tips for Protecting Your WordPress Account
Prioritize your site’s security to prevent future lockouts and security breaches.
Use complex passwords, two-factor authentication, and limit login attempts.
Always keep backups of your WordPress site, so you can restore from a backup if needed.
FAQs Related to WordPress Password Recovery
Can I reset my WordPress password directly from the database?
Yes, you can reset your password using phpMyAdmin by updating the wp_users table and changing the user_pass field using the MD5 function for encryption.
What is the phpMyAdmin tool?
phpMyAdmin is a free software tool written in PHP, that handles the administration of MySQL over the web. It offers various features to manage a MySQL database, making tasks like editing databases much more manageable.
How can I add a new admin user through FTP without access to my WordPress dashboard?
To add a new admin user through FTP, you can insert code into your active theme’s functions.php file that creates a new user and assigns them administrator privileges.
Is it safe to use the Emergency Password Reset Script provided by WordPress?
While it can be safe, it’s crucial only to use the Emergency Password Reset Script in a pinch and to remove it immediately after use to prevent unauthorized access.
What should I do if I’m unable to recover my WordPress admin password?
If all methods fail, contact your hosting provider for assistance, or consider hiring a professional service to help you regain access.
Exploring Alternative Methods for WordPress Password Recovery
At times, the conventional password reset options might not suffice.
Perhaps your website is facing issues with email delivery, or your hosting provider does not offer phpMyAdmin access.
In such cases, alternative methods are vital to reclaim your admin access.
WordPress Functions File Method
By modifying the functions.php file, you can indirectly reset your password.
Add the following function to your active theme’s functions.php file using FTP:
function reset_wp_admin_password() {
$user = get_user_by('login', 'admin');
if ($user) {
wp_set_password('newsecurepassword', $user->ID);
exit('Password has been reset.');
}
}
add_action('init', 'reset_wp_admin_password');
This piece of code will reset the password for the ‘admin’ username.
Do not forget to update ‘admin’ to your username and ‘newsecurepassword’ to your chosen password.
Remember to remove this code immediately after gaining access to avoid security risks.
Reset Password via WP-CLI
If you have access to SSH, WP-CLI is a command-line tool that provides a quicker way to reset passwords.
Use this command to update your password:
wp user update admin --user_pass=newsecurepassword
Replace ‘admin’ with your username, and ‘newsecurepassword’ with your new password.
This method requires WP-CLI to be installed on your server.
MySQL Command Line for Password Reset
For those comfortable with the command line, accessing MySQL directly can be an option.
Login to MySQL, select your WordPress database, and run:
UPDATE wp_users SET user_pass = MD5('newsecurepassword') WHERE user_login = 'admin';
This command resets the password for the ‘admin’ account – adjust the username and password accordingly.
Preventive Measures to Avoid Future Lockouts
Getting locked out of your WordPress admin is a hassle.
To avoid future occurrences, let us explore some preventive strategies.
Implement Two-Factor Authentication
Two-factor authentication adds an extra layer of security to your login process.
It typically requires a secondary code from an app or an SMS to complete the login.
Backup Your WordPress Site
Regular backups can help restore access in case of lockouts or even site compromises.
There are several plugins available to automate this process.
Use a Password Manager
Password managers can store complex passwords securely.
This way, you will not need to remember all your passwords, reducing the risk of getting locked out due to forgotten credentials.
Update Recovery Email Address
Ensure your admin email is current and accessible.
An up-to-date email guarantees you can receive password reset links when required.
Sealing Up WordPress Security Gaps
Prevention is always better than cure, especially when it comes to website security.
Minimizing vulnerabilities is key to protecting your administrative access.
Regularly Update WordPress Core, Themes, and Plugins
Updates often include security fixes.
Regularly updating your WordPress core, themes, and plugins helps patch known vulnerabilities.
Limit Login Attempts
To prevent brute-force attacks, limit the number of failed login attempts.
After a set number of failed tries, the user gets locked out for a certain period.
Change Admin Username
Avoid using ‘admin’ as the username.
Choose a unique username to make it more difficult for attackers to gain access.
FAQs Related to WordPress Password Recovery
Can I use cPanel to reset my WordPress password?
If your hosting provider offers cPanel, you can use its File Manager to edit functions.php or access phpMyAdmin to reset your password via the database.
How often should I change my WordPress password?
While there is no set rule, it is advisable to change your password every 3 to 6 months or in the event of a suspected security breach.
Is it safe to send a password through email?
Emails can be intercepted, so avoid sending passwords through email.
Use password reset links or a secure password manager to share passwords when necessary.
What if I have forgotten both my WordPress admin password and the associated email’s password?
If you have lost access to both, you will need to use FTP, phpMyAdmin, or WP-CLI methods discussed earlier to reset your password.
How can I improve my WordPress password’s strength?
Use a mixture of upper and lowercase letters, numbers, and special characters to create a strong password.
Avoid common words and phrases, and consider using a passphrase.
What should I do if I suspect my WordPress site has been hacked?
In the event of a hack, immediately reset all your passwords, update all software, and review your site files for any malicious changes.
Consider enlisting professional help if the issue persists.
Shop more on Amazon