After the WordPress background password is forgotten, there are N ways to reset and retrieve the password


Forgetting passwords is something that everyone will encounter. After not logging into the WordPress site for a long time, as an administrator, do you often forget the password of the WordPress administrator? It doesn't matter, we can retrieve and reset WordPress user passwords in many ways.

1. Change the password through other administrators

If there is another administrator in your WordPress site, give him a call and ask him to modify it for you. This is the simplest and most convenient method. If he doesn’t know how to modify it, just follow the process below to teach him how to do it. .

  • In the left menu of the WordPress background, click "Users -> All Users"
  • Find your username in the user list and click Edit
  • In the new page that opens, scroll down to the New Password section and click the Generate Password button.
  • You can directly use the generated new password, or enter your commonly used password. If you are using a password you set yourself, it is recommended that the strength be "strong" to ensure WordPress security.
  • Click the "Update Profile" button.

2. Retrieve password via email

If you remember your username or email, you can use WordPress's "recover password" function with common sense.

  • Open the WordPress login page (eg: http://yoursite.com/wordpress/wp-login.php)
  • Click the "Forgot your password?" link
  • Enter your username or email in the new page that opens
  • Then open your mailbox and open the reset password link in the email
  • Enter the new password you want to set and click the "Save" button

If your server cannot send email, this method will not work. After modification through other methods, the SMTP mail server can be set up for later use.

3. Set a new password through the MySQL command line

If you can log into the server via SSH, we can use the MySQL command line to set a new password for the user.

First, we need to use the mysql command line client to log in to the MySQL server. Use the following command to log in:

mysql -u root -p;

Then select the database corresponding to your WordPress site, as follows (wordpress_com is the database name):

use wordpress_com

Finally, use the UPDATE command to update the password. The string after user_pass is the WordPress encrypted password. The corresponding plaintext password in the example below is "123456". Of course, you can generate the WordPress encrypted password string yourself .

UPDATE wp_users SET user_pass = $1$rSziHLDY$399k.JuJsy.oHVp5lquJC. WHERE user_login = '用户名';

This user_pass value also accepts a 32-bit MD5 value. You can use an online MD5 encryption tool to encrypt your password and then fill it in.

4. Add code to reset password in theme file functions.php

Put the following code into the theme file functions.php, visit your WordPress site and the reset will be successful.

$user_id = 1;
$password = 'Hello';
wp_set_password( $password, $user_id );

It should be noted that $user_id needs to be the ID of the administrator account, which is generally 1 by default.

5. Use the official script to reset your password

Save the following code as emergency.php

?php
require './wp-blog-header.php';

function meh() {
	global $wpdb;

	if ( isset( $_POST['update'] ) ) {
		$user_login = ( empty( $_POST['e-name'] ) ? '' : sanitize_user( $_POST['e-name'] ) );
		$user_pass  = ( empty( $_POST[ 'e-pass' ] ) ? '' : $_POST['e-pass'] );
		$answer = ( empty( $user_login ) ? '<div id="message" class="updated fade"><p><strong>用户名不能为空</strong></p></div>' : '' );
		$answer .= ( empty( $user_pass ) ? '<div id="message" class="updated fade"><p><strong>密码不能为空</strong></p></div>' : '' );
		if ( $user_login != $wpdb->get_var( "SELECT user_login FROM $wpdb->users WHERE ID = '1' LIMIT 1" ) ) {
			$answer .="<div id='message' class='updated fade'><p><strong>这不是管理员账号,确保wp_users表里管理账号的ID为1</strong></p></div>";
		}
		if ( empty( $answer ) ) {
			$wpdb->query( "UPDATE $wpdb->users SET user_pass = MD5('$user_pass'), user_activation_key = '' WHERE user_login = '$user_login'" );
			$plaintext_pass = $user_pass;
			$message = "更新后的管理员账号密码如下:\r\n";
			$message  .= sprintf( '用户名: %s', $user_login ) . "\r\n";
			$message .= sprintf( '密码: %s', $plaintext_pass ) . "\r\n";
			@wp_mail( get_option( 'admin_email' ), sprintf( '[%s] 你的WordPress管理员密码重置成功!', get_option( 'blogname' ) ), $message );
			$answer="<div id='message' class='updated fade'><p><strong>你的WordPress管理员密码重置成功!</strong></p><p><strong>密码已通过邮件的方式发送到了你的管理员邮箱</strong></p><p><strong>请现在立即删除这个重置密码脚本!</strong></p></div>";
		}
	}

	return empty( $answer ) ? false : $answer;
}

$answer = meh();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>WordPress 重置密码</title>
	<meta http-equiv="Content-Type" content="<?php bloginfo( 'html_type' ); ?>; charset=<?php bloginfo( 'charset' ); ?>" />
	<link rel="stylesheet" href="<?php bloginfo( 'wpurl' ); ?>/wp-admin/wp-admin.css?version=<?php bloginfo( 'version' ); ?>" type="text/css" />
</head>
<body>
	<div class="wrap">
		<form method="post" action="">
			<h2>WordPress 重置密码</h2>
			<?php
			echo $answer;
			?>

			<fieldset class="options">
				<legend>管理账号</legend>
				<label>用户名<br />
					<input type="text" name="e-name" id="e-name" class="input" value="<?php echo attribute_escape( stripslashes( $_POST['e-name'] ) ); ?>" size="20" tabindex="10" /></label>
				</fieldset>
				<fieldset class="options">
					<legend>密码</legend>
					<label>输入新密码<br />
					<input type="text" name="e-pass" id="e-pass" class="input" value="<?php echo attribute_escape( stripslashes( $_POST['e-pass'] ) ); ?>" size="25" tabindex="20" /></label>
				</fieldset>

				<p class="submit"><input type="submit" name="update" value="修改密码" /></p>
			</form>
		</div>
	</body>
</html>
<?php exit; ?>

Upload emergency.php to the root directory of the website and visit:

http://你的域名/emergency.php

Now, you can change the password on this reset password page, remember to delete this script after the modification is completed!

Guess you like

Origin blog.csdn.net/cljdsc/article/details/132768542