MyBB Community Forums

Full Version: password_changed hook
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi. I want to get the updated password with my plugin. password_changed hook returns the old one. I've tested it with lost password feature. How could I get it updated?

$plugins->add_hook('password_changed', 'foo_update_password');

function foo_update_password()
{
    global $user;
    global $db;
    $username = $user['username'];
    $password = $user['password']; // returns the old password :(
    // more code goes here!
}

Thank you.
You know that user passwords are hashed and salted, right?

[EDIT]
The $user or $mybb->user isn't updated at that time btw.
(2011-06-01, 05:35 PM)Aries-Belgium Wrote: [ -> ]You know that user passwords are hashed and salted, right?

[EDIT]
The $user or $mybb->user isn't updated at that time btw.

Quick reply! Thank you!
Yes, i know.
When is it updated?
(2011-06-01, 05:41 PM)proveyourselfthom Wrote: [ -> ]Quick reply! Thank you!
Yes, i know.
When is it updated?

Probably only at the next time the page reloads but you can fetch the user data straight from the table using the get_user() function:
$user = get_user($uid);
So, i cannot get it updated using a hook... When a user register into myBB i need to get it's information and save it in another database... i want to use the same login in my system and myBB. I did that and it's working fine. The problem is: The user can edit its profile and change password (reset too). Do you have any suggestion to fix my issue?
Thank you.
Like I said, load the information from the database with a query or the get_user() function. You can't use variables that are used in the update_password() function because they are only available in the function scope and not the global scope. And the function also doesn't pass any parameter to the hook.
Ok, but i don't know where should i call it.
Sorry. I don't want to bother you.
Thanks.
Try this:
function foo_update_password()
{
    global $user;
    $_user = get_user($user['uid']);
    // other code
}
(2011-06-01, 06:31 PM)Aries-Belgium Wrote: [ -> ]Try this:
function foo_update_password()
{
    global $user;
    $_user = get_user($user['uid']);
    // other code
}

I've tried it but i got the same old password.
Thank you.
Okay, I toke a look at the code for you. It seems that the update_password() is only used when resetting the password, and not when changing it manually. They use the user datahandler. You can hook into 'datahandler_user_update' hook:
$plugins->add_hook('datahandler_user_update', 'foo_user_update');

function foo_user_update($datahandler)
{
     if(isset($datahandler->user_update_data['password']))
     {
           $password = $datahandler->user_update_data['password'];
     }
}

You can also use that hook when the user changes other data. Although when the password is reset you still have to use the 'password_changed' hook.