0

I'm using woocommerce and customer must be logged or create an account to buy. When they create an account I need to get the password to send the password to my web service and create a new user to my other database.

This database is used for my web application and I have to encrypt the password with the phalcon hash method but I can't do that because the wordpress password is already hashed.

How can I do to do that ?

John
  • 4,711
  • 9
  • 51
  • 101
  • 1
    Why don't you store the passwords in your other database as the Wordpress hash, hashed again with the Phalcon method? – James Paterson Jul 12 '16 at 14:35
  • @JamesPaterson lol makes sense. – mirza Jul 12 '16 at 14:40
  • @JamesPaterson because if you do a phalcon hash on a wordpress hash, on my phalcon application the user password will be the wordpress hash... – John Jul 12 '16 at 15:01
  • @John Do those users need to login into the seperate phalcon web site ? – mirza Jul 12 '16 at 15:17
  • Yes I have 2 Database, one database for wordpress and one database for my phalcon web application and there are on different server. I need the same login/password on my wordpress project and my phalcon project. But the password hash is different between them. Wordpress use wordpress hash and phalcon use phalcon hash. I need to get their password only on the registration or update password – John Jul 12 '16 at 15:24

1 Answers1

1

There is a way to do this. You can have access to users plain password whenever a user logs in but there is no way to get recursively all of the passwords of course. I don't think that would create any problem because functionality will work for the logged users without interruption.

You need to create a hook called as wp_authenticate_user:

add_filter('wp_authenticate_user', 'myplugin_auth_login',10,2); 
// Where $priority is 10, $accepted_args is 2.

function myplugin_auth_login ($user, $password) {

     $user_id = $user->ID;
     // check if passsword is already converted
     $phalcon_hash = get_user_meta( $user_id, 'phalcon_hash' );

     if($phalcon_hash == false) {
      // convert your password with 
      $phalcon_password = use_your_phalcon_hash_method($password);
      // connect your other db and save pass
      send_your_user_info_to_other_db($user_id, $phalcon_password);
      // set user meta as converted
      add_user_meta( $user_id, 'phalcon_hash', true);
     }
}
mirza
  • 5,685
  • 10
  • 43
  • 73