/**
* Setups CRUDlex with some events so the passwords get salted and
* hashed properly.
*
* @param AbstractData $data
* the AbstractData instance managing the users
*
* @param string $passwordField
* the Entity fieldname of the password hash
*
* @param string $saltField
* the Entity fieldname of the password hash salt
*/
public function addEvents(AbstractData $data, $passwordField = 'password', $saltField = 'salt')
{
$that = $this;
$saltGenFunction = function (Entity $entity) use($saltField, $that) {
$salt = $that->getSalt(40);
$entity->set($saltField, $salt);
return true;
};
$data->pushEvent('before', 'create', $saltGenFunction);
$pwHashFunction = $this->getPWHashFunction($data, $passwordField, $saltField);
$data->pushEvent('before', 'create', $pwHashFunction);
$data->pushEvent('before', 'update', $pwHashFunction);
}