在 WordPress 中重置密码后获取新的散列密码

Get new, hashed password after password reset in WordPress

用户在WordPress中重置密码后如何获取新密码的哈希值?

我在我的 functions.php 文件中使用挂钩 after_password_reset,但是 $user->user_pass 提供了 old 散列密码值(密码重置前的散列密码),$new_pass 提供新密码的纯文本(未散列)。

我不明白为什么 $user->user_pass 提供旧密码,因为 hook 是在重置新密码后执行的。

示例代码:

function action_after_password_reset( $user, $new_pass ) {

    $hashed_old_pass = $user->user_pass; // old hashed password, before password reset

    $unhashed_new_pass = $new_pass; // plain text of new password, unhashed

};
add_action( 'after_password_reset', 'action_after_password_reset', 10, 2 ); 

获取存储在数据库中的新密码的准确散列值对我来说很重要。我意识到我可以使用 wp_hash_password($new_pass) 创建新密码的另一个散列,但我想要数据库中的确切散列值。

在操作运行时,用户已在 table 中更新,但内存中的用户对象未更新。

您应该能够像这样从数据库中加载更新后的用户对象:

$updated_user = get_user_by('id', $user->ID);
var_dump($updated_user->user_pass);