WordPress: Recover Access Without Username and Password Have you lost your WordPress username and password? With a simple instruction in the wp-config.php file you can generate a new administrator user and re-enter your site

10 Must-Have features for a WordPress Website in 2019

Losing access to your WordPress site can be frustrating, especially if you can’t log in to the admin panel or use the password recovery tools. However, if you have access to your site’s files, particularly the wp-config.php file, you can create a new administrator user with a simple code modification.

Steps to Create a New Administrator User

If you have lost your username and password but can modify the wp-config.php file, follow these steps:

  1. Access Your Site’s Files
    • Use an FTP client (e.g., FileZilla) or your hosting provider’s File Manager.
    • Locate the root directory of your WordPress installation.
  2. Modify the wp-config.php File
    • Open wp-config.php with a text editor (e.g., Notepad++, VS Code, or cPanel’s file editor).
    • Scroll to the end of the file and add the following line:
      • Replace newUser with your desired username.
      • Replace newPass with your chosen password.
      • Replace [email protected] with a valid email address.
  3. Save the File and Access Your Site
    • Open your browser and visit your WordPress site.
    • The code will execute upon page load, creating the new user.
  4. Log into Your Dashboard
    • Go to https://yourwebsite.com/wp-login.php.
    • Use the credentials you just set (newUser and newPass).
  5. Assign Administrator Privileges (if necessary)
    • Once logged in, navigate to Users > All Users.
    • Edit the new user and set the role to Administrator.
  6. Remove the Code from wp-config.php
    • After regaining access, remove the line of code you added for security reasons.

Alternative Methods

If the above method doesn’t work, you can try other solutions:

  • Using phpMyAdmin to Modify the Database:
    • Log in to your hosting control panel and access phpMyAdmin.
    • Select your WordPress database and open the wp_users table.
    • Create a new user or reset the password of an existing one.
  • Using WP-CLI (if available):
    • Via SSH terminal, run:

Conclusion

This method provides a quick way to regain access to WordPress without resetting the database or reinstalling the site. However, it is crucial to remove the code after logging in to prevent security risks.
Additionally, consider enabling alternative password recovery options, such as email recovery or password managers, to avoid similar issues in the future.

 

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.