In WordPress, you can easily recover and change a user's password if you have access to the user's email or are logged in. But how do you change any user's password if you don't know the administrator's password? In this article, we'll cover a variety of ways to change passwords for different situations.
WordPress Password Storage Mechanism
The user's WordPress password could not be retrieved because it is encoded (hash value) is stored in a database and the only way to retrieve the password from the hash is to brute force it. Such passwords are stored in the database's wp_users
periodic reports user_pass
in the field.
1. Authorized Login - PHP
To access the admin panel without changing the user password, you can use the wp_set_auth_cookie()
Function. The following code shows how to log in as an administrator without changing your password:
if (isset($_GET['login_as_admin'])) {
add_action('init', function() {
$users = get_users(['role' => 'administrator']);
wp_set_auth_cookie($users[0]->ID);
});
}
Insert the above code into the theme's functions.php
file, then go to any page on the site and add the following to the end of the URL login_as_admin
. This code must be deleted when finished to ensure security.
2. Password Change - Admin Panel
![图片[1]-在 WordPress 中更改密码的 8 种有效方法-光子波动网 | 专业WordPress修复服务,全球范围,快速响应](https://www.361sale.com/wp-content/uploads/2024/07/2024072409235864.png)
If you are logged in to the Wordpress dashboard, you can find the Users → Your Profile
page to change your password. If you are an administrator, you can also change your password on the Users → All Users
page to edit any user's password.
3. Password change - e-mail (password recovery)
If you have forgotten your password but have access to the user's e-mail, you can recover it by following these steps:
- Access to the login page
/wp-login.php
The - Click "forgotten password??" Link.
- Enter the email or username for which you need to recover your password.
- Follow the instructions in the email and set a new password via the link.
![图片[2]-在 WordPress 中更改密码的 8 种有效方法-光子波动网 | 专业WordPress修复服务,全球范围,快速响应](https://www.361sale.com/wp-content/uploads/2024/07/2024072409250125.png)
4. Password change - phpMyAdmin
Most hosting providers offer access to phpMyAdmin. Changing your password in phpMyAdmin is very easy:
- go into
wp_users
Table and click on the "Edit" icon next to the user whose password you want to change. - commander-in-chief (military)
user_pass
The value of the field is changed to the MD5 hash of the new password.
Note: The first time you log in, the MD5 hash is automatically updated to the more secure hash used by WordPress.
![图片[3]-在 WordPress 中更改密码的 8 种有效方法-光子波动网 | 专业WordPress修复服务,全球范围,快速响应](https://www.361sale.com/wp-content/uploads/2024/07/2024072409252531.png)
5. Password Change - MySQL
The new password can be set using a SQL query. The following example shows how to change the password of a WordPress administrator:
UPDATE wp_users SET user_pass = MD5('newpass') WHERE user_login = 'admin';
If you have forgotten your login, you can change your password by user ID or e-mail:
UPDATE wp_users SET user_pass = MD5('newpass') WHERE ID = 1;
UPDATE wp_users SET user_pass = MD5('newpass') WHERE user_email = 'admin@example.com';
Before running the above query in the console, you need to connect to the database using the following command:
mysql -user -password -h hostname or IP database name
6. Password change - PHP
You can use PHP code and wp_set_password()
function to set a new password. Insert the following code into the theme's functions.php
Documentation:
if (isset($_GET['init_new_pass_set']) && $login = $_GET['init_new_pass_set']) {
add_action('init', function() use ($login) {
wp_set_password('newpass', get_user_by('login', $login)->ID);
wp_die("Password for user `{$login}` has been changed");;
});
}
After using this code, it must beremoving!
7. Password change - WP-CLI
![图片[4]-在 WordPress 中更改密码的 8 种有效方法-光子波动网 | 专业WordPress修复服务,全球范围,快速响应](https://www.361sale.com/wp-content/uploads/2024/07/2024072409295584.png)
User passwords can be easily set using the WP-CLI. The following example shows how to set a new password for a specified user:
wp user update username --user_pass="new password"
Use the following command to get a list of users:
wp user list
8. Password reset - WP-CLI
Using the WP-CLI, you can set an automatically generated password for a specific user and send a message that the password has been changed. The following example shows how to reset passwords for multiple users:
wp user reset-password admin editor
The user will receive the following e-mail notification that the password has been successfully reset.
![图片[5]-在 WordPress 中更改密码的 8 种有效方法-光子波动网 | 专业WordPress修复服务,全球范围,快速响应](https://www.361sale.com/wp-content/uploads/2024/07/2024072409315186.png)
The above eight methods allow you to securely change the passwords of WordPress users in different situations. Make sure to remove unnecessary code after completing the operation to keep your website secure.
Link to this article:https://www.361sale.com/en/14530The article is copyrighted and must be reproduced with attribution.
No comments