2 require( dirname(__FILE__) . '/wp-config.php' );
4 $action = $_REQUEST['action'];
7 if ( isset($_GET['key']) )
12 header('Content-Type: '.get_bloginfo('html_type').'; charset='.get_bloginfo('charset'));
14 if ( defined('RELOCATE') ) { // Move flag is set
15 if ( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) )
16 $_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] );
18 $schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
19 if ( dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) != get_option('siteurl') )
20 update_option('siteurl', dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) );
23 //Set a cookie now to see if they are supported by the browser.
24 setcookie(TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN);
25 if ( SITECOOKIEPATH != COOKIEPATH )
26 setcookie(TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN);
28 // Rather than duplicating this HTML all over the place, we'll stick it in function
29 function login_header($title = 'Login', $message = '') {
30 global $errors, $error, $wp_locale;
33 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
34 <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
36 <title><?php bloginfo('name'); ?> › <?php echo $title; ?></title>
37 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
38 <?php wp_admin_css(); ?>
39 <!--[if IE]><style type="text/css">#login h1 a { margin-top: 35px; } #login #login_error { margin-bottom: 10px; }</style><![endif]--><!-- Curse you, IE! -->
40 <script type="text/javascript">
42 document.getElementById('user_login').focus();
44 window.onload = focusit;
46 <?php do_action('login_head'); ?>
50 <div id="login"><h1><a href="<?php echo apply_filters('login_headerurl', 'http://wordpress.org/'); ?>" title="<?php echo apply_filters('login_headertitle', __('Powered by WordPress')); ?>"><?php bloginfo('name'); ?></a></h1>
52 if ( !empty( $message ) ) echo apply_filters('login_message', $message) . "\n";
54 // Incase a plugin uses $error rather than the $errors array
55 if ( !empty( $error ) ) {
56 $errors['error'] = $error;
60 if ( !empty( $errors ) ) {
61 if ( is_array( $errors ) ) {
63 foreach ( $errors as $error ) $newerrors .= ' ' . $error . "<br />\n";
67 echo '<div id="login_error">' . apply_filters('login_errors', $errors) . "</div>\n";
69 } // End of login_header()
77 do_action('wp_logout');
79 $redirect_to = 'wp-login.php?loggedout=true';
80 if ( isset( $_REQUEST['redirect_to'] ) )
81 $redirect_to = $_REQUEST['redirect_to'];
83 wp_safe_redirect($redirect_to);
89 case 'retrievepassword' :
94 if ( empty( $_POST['user_login'] ) )
95 $errors['user_login'] = __('<strong>ERROR</strong>: The username field is empty.');
96 if ( empty( $_POST['user_email'] ) )
97 $errors['user_email'] = __('<strong>ERROR</strong>: The e-mail field is empty.');
99 do_action('lostpassword_post');
101 if ( empty( $errors ) ) {
102 $user_data = get_userdatabylogin(trim($_POST['user_login']));
103 // redefining user_login ensures we return the right case in the email
104 $user_login = $user_data->user_login;
105 $user_email = $user_data->user_email;
107 if (!$user_email || $user_email != $_POST['user_email']) {
108 $errors['invalidcombo'] = __('<strong>ERROR</strong>: Invalid username / e-mail combination.');
110 do_action('retreive_password', $user_login); // Misspelled and deprecated
111 do_action('retrieve_password', $user_login);
113 // Generate something random for a password... md5'ing current time with a rand salt
114 $key = substr( md5( uniqid( microtime() ) ), 0, 8);
115 // Now insert the new pass md5'd into the db
116 $wpdb->query("UPDATE $wpdb->users SET user_activation_key = '$key' WHERE user_login = '$user_login'");
117 $message = __('Someone has asked to reset the password for the following site and username.') . "\r\n\r\n";
118 $message .= get_option('siteurl') . "\r\n\r\n";
119 $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
120 $message .= __('To reset your password visit the following address, otherwise just ignore this email and nothing will happen.') . "\r\n\r\n";
121 $message .= get_option('siteurl') . "/wp-login.php?action=rp&key=$key\r\n";
123 if (FALSE == wp_mail($user_email, sprintf(__('[%s] Password Reset'), get_option('blogname')), $message)) {
124 die('<p>' . __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...') . '</p>');
126 wp_redirect('wp-login.php?checkemail=confirm');
133 if ( 'invalidkey' == $_GET['error'] ) $errors['invalidkey'] = __('Sorry, that key does not appear to be valid.');
135 do_action('lost_password');
136 login_header(__('Lost Password'), '<p class="message">' . __('Please enter your username and e-mail address. You will receive a new password via e-mail.') . '</p>');
139 <form name="lostpasswordform" id="lostpasswordform" action="wp-login.php?action=lostpassword" method="post">
141 <label><?php _e('Username:') ?><br />
142 <input type="text" name="user_login" id="user_login" class="input" value="<?php echo attribute_escape(stripslashes($_POST['user_login'])); ?>" size="20" tabindex="10" /></label>
145 <label><?php _e('E-mail:') ?><br />
146 <input type="text" name="user_email" id="user_email" class="input" value="<?php echo attribute_escape(stripslashes($_POST['user_email'])); ?>" size="25" tabindex="20" /></label>
148 <?php do_action('lostpassword_form'); ?>
149 <p class="submit"><input type="submit" name="wp-submit" id="wp-submit" value="<?php _e('Get New Password »'); ?>" tabindex="100" /></p>
154 <?php if (get_option('users_can_register')) : ?>
155 <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php"><?php _e('Login') ?></a></li>
156 <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php?action=register"><?php _e('Register') ?></a></li>
157 <li><a href="<?php bloginfo('url'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('Back to %s'), get_bloginfo('title', 'display' )); ?></a></li>
159 <li><a href="<?php bloginfo('url'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('Back to %s'), get_bloginfo('title', 'display' )); ?></a></li>
160 <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php"><?php _e('Login') ?></a></li>
171 $key = preg_replace('/[^a-z0-9]/i', '', $_GET['key']);
172 if ( empty( $key ) ) {
173 wp_redirect('wp-login.php?action=lostpassword&error=invalidkey');
177 $user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_activation_key = '$key'");
178 if ( empty( $user ) ) {
179 wp_redirect('wp-login.php?action=lostpassword&error=invalidkey');
183 do_action('password_reset');
185 // Generate something random for a password... md5'ing current time with a rand salt
186 $new_pass = substr( md5( uniqid( microtime() ) ), 0, 7);
187 $wpdb->query("UPDATE $wpdb->users SET user_pass = MD5('$new_pass'), user_activation_key = '' WHERE user_login = '$user->user_login'");
188 wp_cache_delete($user->ID, 'users');
189 wp_cache_delete($user->user_login, 'userlogins');
190 $message = sprintf(__('Username: %s'), $user->user_login) . "\r\n";
191 $message .= sprintf(__('Password: %s'), $new_pass) . "\r\n";
192 $message .= get_option('siteurl') . "/wp-login.php\r\n";
194 if (FALSE == wp_mail($user->user_email, sprintf(__('[%s] Your new password'), get_option('blogname')), $message)) {
195 die('<p>' . __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...') . '</p>');
197 // send a copy of password change notification to the admin
198 // but check to see if it's the admin whose password we're changing, and skip this
199 if ($user->user_email != get_option('admin_email')) {
200 $message = sprintf(__('Password Lost and Changed for user: %s'), $user->user_login) . "\r\n";
201 wp_mail(get_option('admin_email'), sprintf(__('[%s] Password Lost/Changed'), get_option('blogname')), $message);
204 wp_redirect('wp-login.php?checkemail=newpass');
210 if ( FALSE == get_option('users_can_register') ) {
211 wp_redirect('wp-login.php?registration=disabled');
216 require_once( ABSPATH . WPINC . '/registration.php');
218 $user_login = sanitize_user( $_POST['user_login'] );
219 $user_email = apply_filters( 'user_registration_email', $_POST['user_email'] );
221 // Check the username
222 if ( $user_login == '' )
223 $errors['user_login'] = __('<strong>ERROR</strong>: Please enter a username.');
224 elseif ( !validate_username( $user_login ) ) {
225 $errors['user_login'] = __('<strong>ERROR</strong>: This username is invalid. Please enter a valid username.');
227 } elseif ( username_exists( $user_login ) )
228 $errors['user_login'] = __('<strong>ERROR</strong>: This username is already registered, please choose another one.');
230 // Check the e-mail address
231 if ($user_email == '') {
232 $errors['user_email'] = __('<strong>ERROR</strong>: Please type your e-mail address.');
233 } elseif ( !is_email( $user_email ) ) {
234 $errors['user_email'] = __('<strong>ERROR</strong>: The email address isn’t correct.');
236 } elseif ( email_exists( $user_email ) )
237 $errors['user_email'] = __('<strong>ERROR</strong>: This email is already registered, please choose another one.');
239 do_action('register_post');
241 $errors = apply_filters( 'registration_errors', $errors );
243 if ( empty( $errors ) ) {
244 $user_pass = substr( md5( uniqid( microtime() ) ), 0, 7);
246 $user_id = wp_create_user( $user_login, $user_pass, $user_email );
248 $errors['registerfail'] = sprintf(__('<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email'));
250 wp_new_user_notification($user_id, $user_pass);
252 wp_redirect('wp-login.php?checkemail=registered');
258 login_header(__('Registration Form'), '<p class="message register">' . __('Register For This Site') . '</p>');
261 <form name="registerform" id="registerform" action="wp-login.php?action=register" method="post">
263 <label><?php _e('Username:') ?><br />
264 <input type="text" name="user_login" id="user_login" class="input" value="<?php echo attribute_escape(stripslashes($user_login)); ?>" size="20" tabindex="10" /></label>
267 <label><?php _e('E-mail:') ?><br />
268 <input type="text" name="user_email" id="user_email" class="input" value="<?php echo attribute_escape(stripslashes($user_email)); ?>" size="25" tabindex="20" /></label>
270 <?php do_action('register_form'); ?>
271 <p id="reg_passmail"><?php _e('A password will be e-mailed to you.') ?></p>
272 <p class="submit"><input type="submit" name="wp-submit" id="wp-submit" value="<?php _e('Register »'); ?>" tabindex="100" /></p>
277 <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php"><?php _e('Login') ?></a></li>
278 <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php?action=lostpassword" title="<?php _e('Password Lost and Found') ?>"><?php _e('Lost your password?') ?></a></li>
279 <li><a href="<?php bloginfo('url'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('Back to %s'), get_bloginfo('title', 'display')); ?></a></li>
291 $using_cookie = FALSE;
293 if ( !isset( $_REQUEST['redirect_to'] ) || is_user_logged_in() )
294 $redirect_to = 'wp-admin/';
296 $redirect_to = $_REQUEST['redirect_to'];
299 $user_login = $_POST['log'];
300 $user_login = sanitize_user( $user_login );
301 $user_pass = $_POST['pwd'];
302 $rememberme = $_POST['rememberme'];
304 $cookie_login = wp_get_cookie_login();
305 if ( ! empty($cookie_login) ) {
306 $using_cookie = true;
307 $user_login = $cookie_login['login'];
308 $user_pass = $cookie_login['password'];
312 do_action_ref_array('wp_authenticate', array(&$user_login, &$user_pass));
314 // If cookies are disabled we can't log in even with a valid user+pass
315 if ( $_POST && empty($_COOKIE[TEST_COOKIE]) )
316 $errors['test_cookie'] = __('<strong>ERROR</strong>: WordPress requires Cookies but your browser does not support them or they are blocked.');
318 if ( $user_login && $user_pass && empty( $errors ) ) {
319 $user = new WP_User(0, $user_login);
321 // If the user can't edit posts, send them to their profile.
322 if ( !$user->has_cap('edit_posts') && ( empty( $redirect_to ) || $redirect_to == 'wp-admin/' ) )
323 $redirect_to = get_option('siteurl') . '/wp-admin/profile.php';
325 if ( wp_login($user_login, $user_pass, $using_cookie) ) {
326 if ( !$using_cookie )
327 wp_setcookie($user_login, $user_pass, false, '', '', $rememberme);
328 do_action('wp_login', $user_login);
329 wp_safe_redirect($redirect_to);
333 $errors['expiredsession'] = __('Your session has expired.');
337 if ( $_POST && empty( $user_login ) )
338 $errors['user_login'] = __('<strong>ERROR</strong>: The username field is empty.');
339 if ( $_POST && empty( $user_pass ) )
340 $errors['user_pass'] = __('<strong>ERROR</strong>: The password field is empty.');
342 // Some parts of this script use the main login form to display a message
343 if ( TRUE == $_GET['loggedout'] ) $errors['loggedout'] = __('Successfully logged you out.');
344 elseif ( 'disabled' == $_GET['registration'] ) $errors['registerdiabled'] = __('User registration is currently not allowed.');
345 elseif ( 'confirm' == $_GET['checkemail'] ) $errors['confirm'] = __('Check your e-mail for the confirmation link.');
346 elseif ( 'newpass' == $_GET['checkemail'] ) $errors['newpass'] = __('Check your e-mail for your new password.');
347 elseif ( 'registered' == $_GET['checkemail'] ) $errors['registered'] = __('Registration complete. Please check your e-mail.');
349 login_header(__('Login'));
352 <form name="loginform" id="loginform" action="wp-login.php" method="post">
353 <?php if ( !in_array( $_GET['checkemail'], array('confirm', 'newpass') ) ) : ?>
355 <label><?php _e('Username:') ?><br />
356 <input type="text" name="log" id="user_login" class="input" value="<?php echo attribute_escape(stripslashes($user_login)); ?>" size="20" tabindex="10" /></label>
359 <label><?php _e('Password:') ?><br />
360 <input type="password" name="pwd" id="user_pass" class="input" value="" size="20" tabindex="20" /></label>
362 <?php do_action('login_form'); ?>
363 <p><label><input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="90" /> <?php _e('Remember me'); ?></label></p>
365 <input type="submit" name="wp-submit" id="wp-submit" value="<?php _e('Login'); ?> »" tabindex="100" />
366 <input type="hidden" name="redirect_to" value="<?php echo attribute_escape($redirect_to); ?>" />
375 <?php if ( in_array( $_GET['checkemail'], array('confirm', 'newpass') ) ) : ?>
376 <li><a href="<?php bloginfo('url'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('Back to %s'), get_bloginfo('title', 'display')); ?></a></li>
377 <?php elseif (get_option('users_can_register')) : ?>
378 <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php?action=register"><?php _e('Register') ?></a></li>
379 <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php?action=lostpassword" title="<?php _e('Password Lost and Found') ?>"><?php _e('Lost your password?') ?></a></li>
380 <li><a href="<?php bloginfo('url'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('Back to %s'), get_bloginfo('title', 'display')); ?></a></li>
382 <li><a href="<?php bloginfo('url'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('Back to %s'), get_bloginfo('title', 'display')); ?></a></li>
383 <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php?action=lostpassword" title="<?php _e('Password Lost and Found') ?>"><?php _e('Lost your password?') ?></a></li>
393 } // end action switch