【问题标题】:Wordpress create account and copy user information to another databaseWordpress 创建帐户并将用户信息复制到另一个数据库
【发布时间】:2016-07-12 13:54:28
【问题描述】:

我正在使用 woocommerce,客户必须登录或创建帐户才能购买。当他们创建帐户时,我需要获取密码以将密码发送到我的网络服务并为我的其他数据库创建一个新用户。

此数据库用于我的 Web 应用程序,我必须使用 phalcon hash method 加密密码,但我不能这样做,因为 wordpress 密码已经被散列。

我该怎么做?

【问题讨论】:

  • 为什么不将密码作为 Wordpress 哈希值存储在其他数据库中,再使用 Phalcon 方法进行哈希处理?
  • @JamesPaterson 哈哈有道理。
  • @JamesPaterson 因为如果你对 wordpress 哈希进行 phalcon 哈希,在我的 phalcon 应用程序上,用户密码将是 wordpress 哈希...
  • @John 这些用户需要登录单独的 phalcon 网站吗?
  • 是的,我有 2 个数据库,一个用于 wordpress 的数据库和一个用于我的 phalcon Web 应用程序的数据库,它们位于不同的服务器上。我的 wordpress 项目和 phalcon 项目需要相同的登录名/密码。但是它们之间的密码哈希是不同的。 Wordpress 使用 wordpress 哈希,phalcon 使用 phalcon 哈希。我只需要在注册或更新密码时获取他们的密码

标签: php wordpress woocommerce phalcon


【解决方案1】:

有办法做到这一点。每当用户登录时,您都可以访问用户的纯密码,但当然无法递归地获取所有密码。我认为这不会造成任何问题,因为功能将在不中断的情况下为登录用户工作。

您需要创建一个名为wp_authenticate_userhook

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);
     }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-24
    相关资源
    最近更新 更多