Jump to content

Logging password changes


maddmac
 Share

Recommended Posts

Is there a method to log when a user's password is changed. For example I would like to log the following 

  • Password changed time/date by which which user
  • Account for a user role changed, what changed and by what user

I realize user logins and attempted logins are made but can the above be added in the same log.

 

 

Link to comment
Share on other sites

You can use the User::changed hook to do what you want (see https://processwire.com/api/ref/wire/changed/).

Put this in site/ready.php:

$wire->addHookAfter('User::changed', function ($event) {
    if($event->arguments(0) === 'pass') {
        $user = $event->object;
        $this->wire->log->save('password-changes', "User $user->name has changed their password");
    }
});

Now everytime a user changes their password, it will be logged to Setup->logs->password-changes.

You can do similar thing with roles

if($event->arguments(0) === 'roles') {
        $user = $event->object;
        $oldRoles = $event->arguments(1);
        $newRoles = $event->arguments(2);
		// code to compare $oldRoles/$newRoles
        // write to log
}

If you want to have that information in the session log, just do $this->wire->log->save('session',...)

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...