Restore WordPress Password Without Access to Email

Tiempo de lectura: 2 minutos

Today we are going to go through the steps to reset a user password in WordPress by generating a new hash and updating it directly in the database, using PHP and MySQL.

Step 1: Access the database

Use a database client like phpMyAdmin or any other method you prefer to access your website’s database.

Step 2: Find the users table

The table containing user information is usually named wp_users (or something similar depending on the table prefix you set during WordPress installation).

Step 3: Generate a new password hash in PHP

We can call it wp-recover.php

<?php
// New plain-text password
$new_password = 'your_new_password';

// Generate password hash
$password_hash = password_hash($new_password, PASSWORD_DEFAULT);

// Print the hash
echo $password_hash;
?>

You can change ‘your_new_password’ to the password you need to set.

We open the address:

https://yoursite.com/wp-recover.php

And the new hash will appear on the screen.

Step 4: Find the user in the database

Use an SQL query to find the user record for which you want to reset the password. This is usually done using the user_login or user_email field.

Step 5: Update the password in the database

Replace the existing value of the password field with the newly generated password hash. Example SQL:

UPDATE wp_users SET user_pass = 'new_password_hash' WHERE user_login = 'username';

Make sure to change “wp_” to the actual prefix of your users table if you have used a different prefix during WordPress installation.

Step 6: Log in with the new password

You should now be able to log in as the user with the new password you have set.

Remember that this method should be used with caution, and it is always advisable to make a backup of your database before making significant changes.

Leave a Comment