【问题标题】:Get new, hashed password after password reset in WordPress在 WordPress 中重置密码后获取新的哈希密码
【发布时间】:2018-12-20 18:08:02
【问题描述】:

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

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

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

示例代码:

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) 来创建新密码的另一个哈希值,但我想要数据库中的确切哈希值。

【问题讨论】:

    标签: wordpress hash passwords reset


    【解决方案1】:

    在动作运行时,用户已经在表中更新,但内存中的用户对象没有更新。

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

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

    【讨论】:

    • 此解决方案效果很好,我已将其标记为已接受的答案。非常感谢,亚历山大。
    猜你喜欢
    • 1970-01-01
    • 2014-07-29
    • 2013-02-27
    • 1970-01-01
    • 1970-01-01
    • 2018-02-27
    • 2020-04-27
    • 2023-04-08
    • 1970-01-01
    相关资源
    最近更新 更多