Monday, 26 November 2012

Change password function in wordpress


function wp_set_password($password,$user_id)
{
       global $wpdb;
       $newpassword = ltrim( $_POST['newpassword']) ;
       $hash = wp_hash_password( $newPassword ) ;
       $wpdb->update( $wpdb->users, array('user_pass' => $hash , 'user_activation_key' => '') , array('ID' => $user_id )) ;

        wp_cache_delete($user_id,'users');
}


 
 

14 comments:

  1. Sir... plz provide sum explanation with all the codes you write..... dat will help to understand the flow..... Thanx in advance

    ReplyDelete
  2. hi brizmohan , wp_set_password is a standard function, i have use above function code in API as - create a function with name changepass that accept three parameter "$currentpass,$newpass,$userid".


    first get the user detail by query
    -> $data = $wpdb->get_row("select * from wp_users where ID='$userid'");

    then validate the user's existing password by wordpress's function -> wp_check_password( $currentpass, $data->user_pass, $data->ID)

    if above function return true. Then use above function code as -

    /* change password */
    global $wpdb;
    $newPassword = ltrim($password);
    $hash = wp_hash_password($newPassword);
    $wpdb->update($wpdb->users, array('user_pass' => $hash, 'user_activation_key' => ''), array('ID' => $access_token['id']) );

    wp_cache_delete($user_id, 'users');
    /* change password ----end */

    And this process change password of user successfully.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me.. 
    python training in velachery | python training institute in chennai

    ReplyDelete
  5. Good Post, I am a big believer in posting comments on sites to let the blog writers know that they ve added something advantageous to the world wide web.
    java training in chennai | java training in bangalore

    java online training | java training in pune

    ReplyDelete
  6. I’m planning to start my blog soon, but I’m a little lost on everything. Would you suggest starting with a free platform like Word Press or go for a paid option? There are so many choices out there that I’m completely confused. Any suggestions? Thanks a lot.

    AWS Training in NewYork City | Amazon Web Services Training in Newyork City
    AWS Training in London | Amazon Web Services Training in London, UK
    Amazon Web Services Online Training in USA | AWS Online Course in USA

    ReplyDelete
  7. I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post.is article. Thanks for sharing nice article about JAVA.
    Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery

    ReplyDelete
  8. I must appreciate you for providing such a valuable content for us. This is one amazing piece of article. Helped a lot in increasing my knowledge..thanks lot!!

    Android Training in Chennai

    Android Online Training in Chennai

    Android Training in Bangalore

    Android Training in Hyderabad

    Android Training in Coimbatore

    Android Training

    Android Online Training

    ReplyDelete