Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/24/2016 02:34:37 PM (9 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.

Props DJPaul, vortfu.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-functions.php

    r10774 r10800  
    18401840        $user_login     = preg_replace( '/\s+/', '', sanitize_user( $user_login, true ) );
    18411841        $user_email     = sanitize_email( $user_email );
    1842         $activation_key = substr( md5( time() . rand() . $user_email ), 0, 16 );
     1842        $activation_key = wp_generate_password( 32, false );
    18431843
    18441844        /**
     
    18621862            }
    18631863
    1864             $activation_key = wp_hash( $user_id );
    18651864            bp_update_user_meta( $user_id, 'activation_key', $activation_key );
    18661865        }
     
    19901989        $user_id = username_exists( $signup->user_login );
    19911990
    1992         // Create the user.
     1991        // Create the user. This should only be necessary if BP_SIGNUPS_SKIP_USER_CREATION is true.
    19931992        if ( ! $user_id ) {
    19941993            $user_id = wp_create_user( $signup->user_login, $password, $signup->user_email );
    19951994
    1996         // If a user ID is found, this may be a legacy signup, or one
    1997         // created locally for backward compatibility. Process it.
    1998         } elseif ( $key == wp_hash( $user_id ) ) {
     1995        // Otherwise, update the existing user's status.
     1996        } elseif ( $key === bp_get_user_meta( $user_id, 'activation_key', true ) || $key === wp_hash( $user_id ) ) {
     1997
    19991998            // Change the user's status so they become active.
    20001999            if ( ! $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 0 WHERE ID = %d", $user_id ) ) ) {
     
    21562155        // Rebuild the activation key, if missing.
    21572156        if ( empty( $signup->activation_key ) ) {
    2158             $signup->activation_key = wp_hash( $signup->ID );
     2157            $signup->activation_key = wp_generate_password( 32, false );
    21592158        }
    21602159
Note: See TracChangeset for help on using the changeset viewer.