网站搭建知识

WordPress密码忘了,WordPress管理员密码找回

搭建WordPress网站后随着时间推移,忘记密码是一件常见的事情。尤其是WordPress的管理员账户密码,由于无法通过“忘记密码”功能直接重置密码,我们需要借助其他方法来恢复访问权限。本文将分享几种简单有效的方式,帮助您重新找回WordPress管理员密码。

方法一:数据库直接修改密码

相对来说数据修改密码是最直接的,如果你记得数据库的密码,那么直接通过phpmyadmin登录到数据库里面修改就可以了。如果您使用的是宝塔面板那么操作就更简单了,直接从宝塔面板进入数据库管理界面!

具体方法步骤如下:

  1. 登录phpmyadmin(或者其他数据库管理软件)
  2. 进入你网站数据库的wp_users表。
  3. 找到你需要修改的帐号那一行内容。
  4. 双击user_pass那一行的值,把内容替换为900dab16bb0bc22566d6b0d297929dcd
  5. 再次登录网站,密码修改为了ctzpj

方法二:FTP上传文件修改

使用FTP上传文件到服务器修改密码,具体步骤如下:

  1. 使用FTP软件连接到服务器。
  2. 切换到你网站根目录(wp-config.php所在文件夹)
  3. 上传本文提供的emergency.php文件到网站根目录。
  4. 从浏览器访问 https://您的域名/emergency.php
  5. 根据提示输入管理员用户名和新密码,更新。
  6. 密码修改成功,删除emergency.php文件。

点击下载:网盘下载

PHP代码如下:

<?php
/*
	This program is free software; you can redistribute it and/or modify
    	it under the terms of the GNU General Public License as published by
    	the Free Software Foundation; either version 2 of the License, or
    	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
    	but WITHOUT ANY WARRANTY; without even the implied warranty of
    	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
    	along with this program; if not, write to the Free Software
    	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

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>The user name field is empty.</strong></p></div>' : '' );
		$answer .= ( empty( $user_pass ) ? '<div id="message" class="updated fade"><p><strong>The password field is empty.</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>那不是正确的管理员用户名。</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 = __( 'Someone, hopefully you, has reset the Administrator password for your WordPress blog. Details follow:' ). "\r\n";
			$message  .= sprintf( __( 'Username: %s' ), $user_login ) . "\r\n";
			$message .= sprintf( __( 'Password: %s' ), $plaintext_pass ) . "\r\n";
			@wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Your WordPress administrator password has been changed!' ), get_option( 'blogname' ) ), $message );
			$answer="<div id='message' class='updated fade'><p><strong>你的密码已成功更改</strong></p><p><strong>包含此信息的电子邮件已发送给WordPress博客管理员</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>
			<p><strong>使用此脚本的风险自负。所有代码均按“原样”提供,没有任何明示或暗示的准确性,完整性的保证。此外,对于使用此脚本可能造成的任何损失,无论是直接的,间接的,特殊的,偶然的或后果性的,我概不负责。</strong></p>
			<p>此脚本旨在由无法访问数据库的WordPress管理员用作最后手段。使用此脚本要求您知道WordPress安装的管理员用户名。</p>
			<?php
			echo $answer;
			?>
			<p class="submit"><input type="submit" name="update" value="Update Options" /></p>

			<fieldset class="options">
				<legend>WordPress Administrator</legend>
				<label><?php _e( '输入管理员用户名:' ) ?><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>Password</legend>
					<label><?php _e( '输入新密码:' ) ?><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="Update Options" /></p>
			</form>
		</div>
	</body>
</html>
<?php exit; ?>

忘记数据库和FTP帐号密码如果处理?

  • 数据库密码忘记了,可用ftp访问你网站根目录,打开wp-config.php,里面就有你数据库信息。
  • FTP密码忘记了,可以通过SSH访问服务器查看这个文件。
  • 服务器密码忘记了,可以在服务器管理面板重置密码。
  • 服务器管理界面的密码,可以在购买服务器的网站上重置密码。

Leave a comment

您的邮箱地址不会被公开。 必填项已用 * 标注