Skip to:
Content

BuddyPress.org

Changeset 10801


Ignore:
Timestamp:
05/24/2016 02:45:08 PM (10 years ago)
Author:
boonebgorges
Message:

Better hash building for activation keys, password reset keys, and filenames.

There is no need to use user-facing info for these hashes.

Ports [10800] to the 2.5 branch.

Props DJPaul, vortfu.

Location:
branches/2.5
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/2.5

    • Property svn:mergeinfo changed
      /trunk (added)merged: 10800
  • branches/2.5/src/bp-core/classes/class-bp-attachment-avatar.php

    r10417 r10801  
    293293            }
    294294
    295             $args['dst_file'] = $avatar_folder_dir . '/' . wp_hash( $absolute_path . time() ) . '-bp' . $key_type . '.' . $ext;
     295            $filename         = wp_unique_filename( $avatar_folder_dir, uniqid() . "-bp{$key_type}.{$ext}" );
     296            $args['dst_file'] = $avatar_folder_dir . '/' . $filename;
    296297
    297298            $avatar_types[ $key_type ] = parent::crop( $args );
  • branches/2.5/src/bp-core/classes/class-bp-attachment-cover-image.php

    r10417 r10801  
    209209        }
    210210
    211         $info    = pathinfo( $file );
    212         $dir     = $info['dirname'];
    213         $ext     = strtolower( $info['extension'] );
    214         $name    = wp_hash( $file . time() ) . '-bp-cover-image';
    215 
    216         return trailingslashit( $dir ) . "{$name}.{$ext}";
     211        $info = pathinfo( $file );
     212        $ext  = strtolower( $info['extension'] );
     213        $name = wp_unique_filename( $info['dirname'], uniqid() . "-bp-cover-image.$ext" );
     214
     215        return trailingslashit( $info['dirname'] ) . $name;
    217216    }
    218217
  • branches/2.5/src/bp-members/bp-members-functions.php

    r10601 r10801  
    17921792        $user_login     = preg_replace( '/\s+/', '', sanitize_user( $user_login, true ) );
    17931793        $user_email     = sanitize_email( $user_email );
    1794         $activation_key = substr( md5( time() . rand() . $user_email ), 0, 16 );
     1794        $activation_key = wp_generate_password( 32, false );
    17951795
    17961796        /**
     
    18141814            }
    18151815
    1816             $activation_key = wp_hash( $user_id );
    18171816            bp_update_user_meta( $user_id, 'activation_key', $activation_key );
    18181817        }
     
    19381937        $user_id = username_exists( $signup->user_login );
    19391938
    1940         // Create the user.
     1939        // Create the user. This should only be necessary if BP_SIGNUPS_SKIP_USER_CREATION is true.
    19411940        if ( ! $user_id ) {
    19421941            $user_id = wp_create_user( $signup->user_login, $password, $signup->user_email );
    19431942
    1944         // If a user ID is found, this may be a legacy signup, or one
    1945         // created locally for backward compatibility. Process it.
    1946         } elseif ( $key == wp_hash( $user_id ) ) {
     1943        // Otherwise, update the existing user's status.
     1944        } elseif ( $key === bp_get_user_meta( $user_id, 'activation_key', true ) || $key === wp_hash( $user_id ) ) {
     1945
    19471946            // Change the user's status so they become active.
    19481947            if ( ! $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 0 WHERE ID = %d", $user_id ) ) ) {
     
    21042103        // Rebuild the activation key, if missing.
    21052104        if ( empty( $signup->activation_key ) ) {
    2106             $signup->activation_key = wp_hash( $signup->ID );
     2105            $signup->activation_key = wp_generate_password( 32, false );
    21072106        }
    21082107
  • branches/2.5/src/bp-members/bp-members-screens.php

    r10521 r10801  
    360360        }
    361361
    362         $hashed_key = wp_hash( $key );
    363 
    364         // Check if the signup avatar folder exists. If it does, move the folder to
    365         // the BP user avatars directory.
    366         if ( file_exists( bp_core_avatar_upload_path() . '/avatars/signups/' . $hashed_key ) ) {
    367             @rename( bp_core_avatar_upload_path() . '/avatars/signups/' . $hashed_key, bp_core_avatar_upload_path() . '/avatars/' . $user );
    368         }
    369 
    370362        bp_core_add_message( __( 'Your account is now active!', 'buddypress' ) );
    371363        $bp->activation_complete = true;
  • branches/2.5/src/bp-members/classes/class-bp-signup.php

    r10597 r10801  
    737737            $user_id = username_exists( $signup->user_login );
    738738
    739             if ( ! empty( $user_id ) && $signup->activation_key == wp_hash( $user_id ) ) {
     739            if ( ! empty( $user_id ) && $signup->activation_key === bp_get_user_meta( $user_id, 'activation_key', true ) ) {
    740740
    741741                if ( 2 != self::check_user_status( $user_id ) ) {
  • branches/2.5/src/bp-settings/bp-settings-actions.php

    r10498 r10801  
    9595                // Store a hash to enable email validation.
    9696                if ( false === $email_error ) {
    97                     $hash = wp_hash( $_POST['email'] );
     97                    $hash = wp_generate_password( 32, false );
    9898
    9999                    $pending_email = array(
  • branches/2.5/tests/phpunit/testcases/members/functions.php

    r9819 r10801  
    262262
    263263        // Fake an old-style registration
    264         $key = wp_hash( $u_obj->ID );
     264        $key = wp_generate_password( 32, false );
    265265        update_user_meta( $u, 'activation_key', $key );
    266266
     
    296296
    297297        // Fake an old-style registration
    298         $key = wp_hash( $u_obj->ID );
     298        $key = wp_generate_password( 32, false );
    299299        update_user_meta( $u, 'activation_key', $key );
    300300
Note: See TracChangeset for help on using the changeset viewer.