<?php /**
* WordPress User Page
*
* Handles authentication, registering, resetting passwords, forgot password,
* and other user handling.
*
* @package WordPress
*/
/** Make sure that the WordPress bootstrap has ran before continuing. */ require(dirname(__FILE__).'/wp-load.php');
// Redirect to https login if forced to use SSL if( force_ssl_admin()&&!is_ssl()){ if(0===strpos($_SERVER['REQUEST_URI'],'http')){
wp_redirect(preg_replace('|^http://|','https://',$_SERVER['REQUEST_URI'])); exit(); }else{
wp_redirect('https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); exit(); } }
/**
* login_header() - Outputs the header for the login page
*
* @package WordPress
* @uses do_action() Calls the 'login_head' for outputting HTML in the Login
* header.
* @uses apply_filters() Calls 'login_headerurl' for the top login link.
* @uses apply_filters() Calls 'login_headertitle' for the top login title.
* @uses apply_filters() Calls 'login_message' on the message to display in the
* header.
* @uses $error The error global, which is checked for displaying errors.
*
* @param string $title Optional. WordPress Login Page title to display in
* <title/> element.
* @param string $message Optional. Message to display in header.
* @param WP_Error $wp_error Optional. WordPress Error Object
*/ function login_header($title='Login',$message='',$wp_error=''){ global$error;
/**
* retrieve_password() - Handles sending password retrieval email to user
*
* {@internal Missing Long Description}}
*
* @uses $wpdb WordPress Database object
*
* @return bool|WP_Error True: when finish. WP_Error on error
*/ function retrieve_password(){ global$wpdb;
$errors=new WP_Error();
if(empty($_POST['user_login'])&&empty($_POST['user_email'])) $errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or e-mail address.'));
if(strstr($_POST['user_login'],'@')){ $user_data= get_user_by_email(trim($_POST['user_login'])); if(empty($user_data)) $errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.')); }else{ $login=trim($_POST['user_login']); $user_data= get_userdatabylogin($login); }
do_action('lostpassword_post');
if($errors->get_error_code()) return$errors;
if(!$user_data){ $errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or e-mail.')); return$errors; }
// redefining user_login ensures we return the right case in the email $user_login=$user_data->user_login; $user_email=$user_data->user_email;
do_action('retreive_password',$user_login);// Misspelled and deprecated
do_action('retrieve_password',$user_login);
if(!$allow) returnnew WP_Error('no_password_reset', __('Password reset is not allowed for this user')); elseif( is_wp_error($allow)) return$allow;
$key=$wpdb->get_var($wpdb->prepare("SELECT user_activation_key FROM $wpdb->users WHERE user_login = %s",$user_login)); if(empty($key)){ // Generate something random for a key... $key= wp_generate_password(20,false);
do_action('retrieve_password_key',$user_login,$key); // Now insert the new md5 key into the db $wpdb->query($wpdb->prepare("UPDATE $wpdb->users SET user_activation_key = %s WHERE user_login = %s",$key,$user_login)); } $message= __('Someone has asked to reset the password for the following site and username.')."\r\n\r\n"; $message.= get_option('siteurl')."\r\n\r\n"; $message.=sprintf(__('Username: %s'),$user_login)."\r\n\r\n"; $message.= __('To reset your password visit the following address, otherwise just ignore this email and nothing will happen.')."\r\n\r\n"; $message.= site_url("wp-login.php?action=rp&key=$key",'login')."\r\n";
if(!wp_mail($user_email,sprintf(__('[%s] Password Reset'), get_option('blogname')),$message)) die('<p>'. __('The e-mail could not be sent.')."<br />\n". __('Possible reason: your host may have disabled the mail() function...').'</p>');
returntrue; }
/**
* reset_password() - Handles resetting the user's password
*
* {@internal Missing Long Description}}
*
* @uses $wpdb WordPress Database object
*
* @param string $key Hash to validate sending user's password
* @return bool|WP_Error
*/ function reset_password($key){ global$wpdb;
$user=$wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s",$key)); if(empty($user)) returnnew WP_Error('invalid_key', __('Invalid key'));
do_action('password_reset',$user);
// Generate something random for a password... $new_pass= wp_generate_password();
wp_set_password($new_pass,$user->ID); $message=sprintf(__('Username: %s'),$user->user_login)."\r\n"; $message.=sprintf(__('Password: %s'),$new_pass)."\r\n"; $message.= site_url('wp-login.php','login')."\r\n";
if(!wp_mail($user->user_email,sprintf(__('[%s] Your new password'), get_option('blogname')),$message)) die('<p>'. __('The e-mail could not be sent.')."<br />\n". __('Possible reason: your host may have disabled the mail() function...').'</p>');
// send a copy of password change notification to the admin // but check to see if it's the admin whose password we're changing, and skip this if($user->user_email!= get_option('admin_email')){ $message=sprintf(__('Password Lost and Changed for user: %s'),$user->user_login)."\r\n";
wp_mail(get_option('admin_email'),sprintf(__('[%s] Password Lost/Changed'), get_option('blogname')),$message); }
returntrue; }
/**
* register_new_user() - Handles registering a new user
*
* {@internal Missing Long Description}}
*
* @param string $user_login User's username for logging in
* @param string $user_email User's email address to send password and add
* @return int|WP_Error Either user's ID or error on failure.
*/ function register_new_user($user_login,$user_email){ $errors=new WP_Error();
// Check the username if($user_login=='') $errors->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.')); elseif(!validate_username($user_login)){ $errors->add('invalid_username', __('<strong>ERROR</strong>: This username is invalid. Please enter a valid username.')); $user_login=''; }elseif( username_exists($user_login)) $errors->add('username_exists', __('<strong>ERROR</strong>: This username is already registered, please choose another one.'));
// Check the e-mail address if($user_email==''){ $errors->add('empty_email', __('<strong>ERROR</strong>: Please type your e-mail address.')); }elseif(!is_email($user_email)){ $errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn’t correct.')); $user_email=''; }elseif( email_exists($user_email)) $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.'));
if(defined('RELOCATE')){// Move flag is set if(isset($_SERVER['PATH_INFO'])&&($_SERVER['PATH_INFO']!=$_SERVER['PHP_SELF'])) $_SERVER['PHP_SELF']=str_replace($_SERVER['PATH_INFO'],'',$_SERVER['PHP_SELF']);
//Set a cookie now to see if they are supported by the browser. setcookie(TEST_COOKIE,'WP Cookie check',0, COOKIEPATH, COOKIE_DOMAIN); if( SITECOOKIEPATH != COOKIEPATH ) setcookie(TEST_COOKIE,'WP Cookie check',0, SITECOOKIEPATH, COOKIE_DOMAIN);
if('invalidkey'==$_GET['error'])$errors->add('invalidkey', __('Sorry, that key does not appear to be valid.'));
do_action('lost_password');
login_header(__('Lost Password'),'<p class="message">'. __('Please enter your username or e-mail address. You will receive a new password via e-mail.').'</p>',$errors); ?>
if(!is_wp_error($user)){ // If the user can't edit posts, send them to their profile. if(!$user->has_cap('edit_posts')&&(empty($redirect_to)||$redirect_to=='wp-admin/')) $redirect_to= admin_url('profile.php');
wp_safe_redirect($redirect_to); exit(); }
$errors=$user; // Clear errors if loggedout is set. if(!empty($_GET['loggedout'])) $errors=new WP_Error();
// If cookies are disabled we can't log in even with a valid user+pass if(isset($_POST['testcookie'])&&empty($_COOKIE[TEST_COOKIE])) $errors->add('test_cookie', __("<strong>ERROR</strong>: Cookies are blocked or not supported by your browser. You must <a href='http://www.google.com/cookies.html'>enable cookies</a> to use WordPress."));
// Some parts of this script use the main login form to display a message if(isset($_GET['loggedout'])&&TRUE==$_GET['loggedout'])$errors->add('loggedout', __('You are now logged out.'),'message'); elseif(isset($_GET['registration'])&&'disabled'==$_GET['registration'])$errors->add('registerdiabled', __('User registration is currently not allowed.')); elseif(isset($_GET['checkemail'])&&'confirm'==$_GET['checkemail'])$errors->add('confirm', __('Check your e-mail for the confirmation link.'),'message'); elseif(isset($_GET['checkemail'])&&'newpass'==$_GET['checkemail'])$errors->add('newpass', __('Check your e-mail for your new password.'),'message'); elseif(isset($_GET['checkemail'])&&'registered'==$_GET['checkemail'])$errors->add('registered', __('Registration complete. Please check your e-mail.'),'message');