1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Wordpress change password

Discussion in 'PHP' started by epikpoker, Nov 25, 2010.

  1. #1
    Hi, I am trying to write a function to allow users to change there password from the front end of my site. Since I last worked with the login system it looks like wordpress has changed from md5 encryption.

    Anyone have any idea what encryption is being used? or better yet the function that creates these passwords? (not wp_generate_password)
    SEMrush
    Thanks!
     
    epikpoker, Nov 25, 2010 IP
    SEMrush
  2. drctaccess

    drctaccess Peon

    Messages:
    62
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Use this

    <?php
    require_once( 'wp-load.php' );
    require_once( 'wp-includes/wp-db.php');
    require_once( 'wp-includes/registration.php');

    function change_password($userdata) {
    $ID = (int) $userdata['ID'];

    $user = get_userdata($ID);

    $user = add_magic_quotes(get_object_vars($user));

    if ( ! empty($userdata['user_pass']) ) {
    $plaintext_pass = $userdata['user_pass'];
    $userdata['user_pass'] = wp_hash_password($userdata['user_pass']);
    }

    wp_cache_delete($user[ 'user_email' ], 'useremail');

    $userdata = array_merge($user, $userdata);
    $user_id = wp_insert_user($userdata);

    $current_user = wp_get_current_user();
    if ( $current_user->id == $ID ) {
    if ( isset($plaintext_pass) ) {
    wp_clear_auth_cookie();
    wp_set_auth_cookie($ID);
    }
    }

    return 'Password changed';
    }

    //set the parameters for the user you want to change the password (ID and new password)

    $user['ID'] = 1;
    $user['user_pass'] = '123456';

    echo change_password($user);

    ?>


    I assumed that above script will be placed in the root of your wordpress folder .. if you want to place the script in another area.. please be sure that the paths in require_once function get updated as well.

    I hope this one helps.
     
    drctaccess, Nov 26, 2010 IP
  3. epikpoker

    epikpoker Active Member

    Messages:
    213
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    66
    #3
    This is awesome, thanks so much.
     
    epikpoker, Nov 26, 2010 IP
  4. puya4ever

    puya4ever Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes. Thanks you. I spent much time to change my WP password from wp-admin.
     
    puya4ever, Nov 27, 2010 IP