I don’t think you need most of that.
In OnSaveUser, you should be able to test for a new user and get the password hash from the $user object and OnUserChangePassword will fire if an existing user changes passwords. Be sure to connect the plugin to both OnUserSave and OnUserChangePassword.
<?php
$update = false;
switch ($modx->event->name) {
case 'OnUserSave':
if ($mode == modSystemEvent::MODE_NEW) {
$update = true;
break;
case 'OnUserChangePassword':
$update = true;
break;
}
if ($update) {
$pwd = $user->get('password');
/* do your stuff here -- $pwd will be set */
}
Note that what’s stored in the password field is not the password, but a hash of the password.
If you’re using Revolution, you might also want to pay attention to $user->get(’hash_class’), which will be either hashing.modMD5 or hashing.modPDKBF2. As of 2.1, MODX uses PDKBF2. For converted sites from previous versions, however, existing users have MD5 hashes.