1
votes

Is there a TYPO3 backend hook to check if the fe_users password was changed? I tried this:

public function processDatamap_preProcessFieldArray(array &$fieldArray, $table, $id, \TYPO3\CMS\Core\DataHandling\DataHandler &$pObj) {
    if ($table === "fe_users" && stripos($id, 'NEW') === false){
        $pw = $fieldArray['password'];
        die($pw);
    }
}

The problem is, this always returns a password, either the new one or a hashed one if it already existed, so I wouldn't know if its a changed field or not. Is there a way to check for changed fields?

1
please be more specific what you mean with "changed"! Changed from what (earlier value)? and changed where? as you compare $id with 'NEW' I assume that it is about a new creation of fe_users, but fe_users could be created in multiple ways. from BE up to different extensions in the FE, and each FE-Extension has a lot of options.Bernd Wilke πφ
no it is NOT about new entries, its when someone edits a user in the backend - I want to see after saving if the password was changed or not. Did the editor leave the password as it was or did he enter a new one?Chi

1 Answers

0
votes

Seems like I found a solution. Not sure if it's the best but so far it works. I realized, that processDatamap_preProcessFieldArray is where the password is still available in plain text, so I need to use it to store the password (later it is already hashed, therefore unusable for me) using the registry.

The fieldArray values in processDatamap_afterDatabaseOperations are only set, when a value was changed, so by checking if the password key was set, I know if the password was initially changed or not.

So this is what my solution looks like:

public function processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, $pObj) {
    if ($table === "fe_users" && $status === "update" && isset($fieldArray['password'])) {
        //get the password
        $registry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Registry');
        $pw = $registry->get('be', 'lastPassword');

        //do whatever is necessary with the plain text password...

        //remove it
        $registry->remove('be', 'lastPassword');
    }
}

public function processDatamap_preProcessFieldArray(array &$fieldArray, $table, $id, \TYPO3\CMS\Core\DataHandling\DataHandler &$pObj) {
    if ($table === "fe_users" && stripos($id, 'NEW') === false){
        $pw = $fieldArray['password'];
        $registry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Registry');
        $registry->set('be', 'lastPassword', $pw);
    }
}