워드프레스 비밀번호 재설정 스크립트 (DB에 접속할 수 없는 경우)

워드프레스 Codex 사이트에 올라온 긴급 시 사용할 수 있는 워드프레스 비밀번호 재설정 스크립트입니다. 아마 Emergency라는 이름의 플러그인으로 만들어졌지만 현재는 워드프레스 저장소에서 제거된 것 같습니다. 아래에 소개하는 스크립트를 사용하는 경우 주의하여 사용하시기 바랍니다.

워드프레스 비밀번호 재설정 스크립트 (DB에 접속할 수 없는 경우)

워드프레스 관리자 비밀번호가 기억이 나지 않아서 관리자 페이지에 로그인하지 못하는 경우 이메일을 통해 패스워드 재설정 링크를 받을 수 있습니다. 어떤 이유로 이메일이 전송되지 않는다면 phpMyAdminMySQL 클라이언트에 접속하여 비번을 재설정할 수 있습니다.

DB에 접속할 수 없는 경우 아래의 스크립트를 사용할 수 있습니다. 하지만 조심해서 사용하시기 바랍니다.

경고

  1. 관리자 사용자 이름(username)을 알고 있어야 합니다. 모르는 경우 사용할 수 없습니다.
  2. 아래 스크립트를 이용하면 어드민 패스워드를 업데이트하고 관리자의 이메일 주소로 전송됩니다.
  3. 이메일로 받지 못하더라도 비밀번호는 변경됩니다.
  4. 로그인을 할 수 있게 되면 스크립트가 더 이상 필요하지 않습니다.
  5. 워드프레스가 설치된 루트 폴더에 이 스크립트를 위치합니다. 워드프레스 플러그인 디렉터리로 업로드하지 않도록 합니다.
  6. 완료되면 보안을 위해 스크립트를 삭제하세요.

사용 방법

  1. 스크립트를 emergency.php라는 파일로 워드프레스가 설치된 루트 폴더(wp-config.php 파일이 있는 디렉터리)에 저장합니다.
  2. 브라우저에서 http://example.com/emergency.php를 엽니다.
  3. 화면이 표시되면 관리자 사용자명(예: admin)과 비밀번호를 입력한 다음, Update Options를 클릭합니다. 비밀번호가 변경된다는 메시지가 표시되고, 변경된 비밀번호 정보가 블로그 관리자에게 이메일로 전송됩니다.
  4. 작업이 완료되면 emergency.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.

       이 프로그램은 무료 소프트웨어입니다.자유 소프트웨어 재단(Free 
        Software Foundation)에 의해 공표된 대로 GNU General Public License
        (해당 License의 버전 2, 또는 최신 버전)의 조건에 따라 
        이 프로그램을 재배포하거나 변경할 수 있습니다.

	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>That is not the correct administrator username.</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>Your password has been successfully changed</strong></p><p><strong>An e-mail with this information has been dispatched to the WordPress blog administrator</strong></p><p><strong>You should now delete this file off your server. DO NOT LEAVE IT UP FOR SOMEONE ELSE TO FIND!</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 Emergency PassWord Reset</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 Emergency PassWord Reset</h2>
			<p><strong>Your use of this script is at your sole risk. All code is provided "as -is", without any warranty, whether express or implied, of its accuracy, completeness. Further, I shall not be liable for any damages you may sustain by using this script, whether direct, indirect, special, incidental or consequential.</strong></p>
			<p>This script is intended to be used as <strong>a last resort</strong> by WordPress administrators that are unable to access the database.
				Usage of this script requires that you know the Administrator's user name for the WordPress install. (For most installs, that is going to be "admin" without the quotes.)</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( 'Enter Username:' ) ?><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( 'Enter New Password:' ) ?><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; ?>

// 출처: https://codex.wordpress.org/User:MichaelH/Orphaned_Plugins_needing_Adoption/Emergency

혹시 모르니 가능한 경우 사이트 전체를 백업한 후에 위의 코드를 사용하시기 바랍니다.

가능한 경우 phpMyAdmin에 로그인하여 관리자 비밀번호를 변경할 수 있습니다. 디비에 접속할 수 없는 경우 위의 방법을 시도해볼 수 있지만, ID가 "1"인 관리자 유저네임을 알고 있어야 변경이 가능합니다.

비밀번호 변경과 관련하여 어려움을 겪는 경우 여기에서 서비스(유료)를 의뢰하실 수 있습니다.

참고

일부 글에 제휴 링크가 포함될 수 있으며 파트너스 활동으로 일정액의 수수료를 받을 수 있습니다.

댓글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다