Make WordPress Core

Ticket #13655: stripslash-passwords-take-1-fixed.patch

File stripslash-passwords-take-1-fixed.patch, 4.4 KB (added by johanee, 14 years ago)

Fixed patch using approach 1 (stripslash password input at once)

  • wp-login.php

     
    461461        if ( isset($_POST['pass1']) && $_POST['pass1'] != $_POST['pass2'] ) {
    462462                $errors = new WP_Error('password_reset_mismatch', __('The passwords do not match.'));
    463463        } elseif ( isset($_POST['pass1']) && !empty($_POST['pass1']) ) {
    464                 reset_password($user, $_POST['pass1']);
     464                reset_password($user, stripslashes($_POST['pass1']));
    465465                login_header(__('Password Reset'), '<p class="message reset-pass">' . __('Your password has been reset.') . ' <a href="' . site_url('wp-login.php', 'login') . '">' . __('Log in') . '</a></p>');
    466466                login_footer();
    467467                exit;
  • wp-includes/user.php

     
    2727                if ( ! empty($_POST['log']) )
    2828                        $credentials['user_login'] = $_POST['log'];
    2929                if ( ! empty($_POST['pwd']) )
    30                         $credentials['user_password'] = $_POST['pwd'];
     30                        $credentials['user_password'] = stripslashes($_POST['pwd']);
    3131                if ( ! empty($_POST['rememberme']) )
    3232                        $credentials['remember'] = $_POST['rememberme'];
    3333        }
  • wp-includes/pluggable.php

     
    14591459function wp_check_password($password, $hash, $user_id = '') {
    14601460        global $wp_hasher;
    14611461
     1462        /*
     1463         * For a long time WordPress did not stripslash() passwords in $_POST.
     1464         * To handle password hashes created during that time we must therefore
     1465         * also check against addslashed passwords and update hash on match.
     1466         */
     1467
    14621468        // If the hash is still md5...
    14631469        if ( strlen($hash) <= 32 ) {
    14641470                $check = ( $hash == md5($password) );
     1471                if (!$check)
     1472                        $check = ( $hash == md5(addslashes($password)) );
    14651473                if ( $check && $user_id ) {
    14661474                        // Rehash using new hash.
    14671475                        wp_set_password($password, $user_id);
     
    14811489
    14821490        $check = $wp_hasher->CheckPassword($password, $hash);
    14831491
     1492        // Also check using slashed password, and migrate if necessary
     1493        if ( !$check && $user_id ) {
     1494                $check = $wp_hasher->CheckPassword(addslashes($password), $hash);
     1495                if ( $check  ) {
     1496                        // Rehash with correct password
     1497                        wp_set_password($password, $user_id);
     1498                        $hash = wp_hash_password($password);
     1499                }
     1500        }
     1501
    14841502        return apply_filters('check_password', $check, $password, $hash, $user_id);
    14851503}
    14861504endif;
  • wp-admin/includes/user.php

     
    7070
    7171        $pass1 = $pass2 = '';
    7272        if ( isset( $_POST['pass1'] ))
    73                 $pass1 = $_POST['pass1'];
     73                $pass1 = stripslashes($_POST['pass1']);
    7474        if ( isset( $_POST['pass2'] ))
    75                 $pass2 = $_POST['pass2'];
     75                $pass2 = stripslashes($_POST['pass2']);
    7676
    7777        if ( isset( $_POST['role'] ) && current_user_can( 'edit_users' ) ) {
    7878                $new_role = sanitize_text_field( $_POST['role'] );
     
    148148        }
    149149
    150150        /* Check for "\" in password */
    151         if ( false !== strpos( stripslashes($pass1), "\\" ) )
     151        if ( false !== strpos( $pass1, "\\" ) )
    152152                $errors->add( 'pass', __( '<strong>ERROR</strong>: Passwords may not contain the character "\\".' ), array( 'form-field' => 'pass1' ) );
    153153
    154154        /* checking the password has been typed twice the same */
  • wp-admin/install.php

     
    183183                // Fill in the data we gathered
    184184                $weblog_title = isset( $_POST['weblog_title'] ) ? trim( stripslashes( $_POST['weblog_title'] ) ) : '';
    185185                $user_name = isset($_POST['user_name']) ? trim( stripslashes( $_POST['user_name'] ) ) : 'admin';
    186                 $admin_password = isset($_POST['admin_password']) ? $_POST['admin_password'] : '';
    187                 $admin_password_check = isset($_POST['admin_password2']) ? $_POST['admin_password2'] : '';
     186                $admin_password = isset($_POST['admin_password']) ? trim( stripslashes( $_POST['admin_password'] ) ) : '';
     187                $admin_password_check = isset($_POST['admin_password2']) ? trim( stripslashes( $_POST['admin_password2'] ) ) : '';
    188188                $admin_email  = isset( $_POST['admin_email']  ) ?trim( stripslashes( $_POST['admin_email'] ) ) : '';
    189189                $public       = isset( $_POST['blog_public']  ) ? (int) $_POST['blog_public'] : 0;
    190190                // check e-mail address