src/Model/Behavior/PasswordableBehavior.php
public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $options) {
		$formField = $this->_config['formField'];
		$field = $this->_config['field'];

		$PasswordHasher = $this->_getPasswordHasher($this->_config['passwordHasher']);

		if ($entity->get($formField) !== null) {
			$entity->set($field, $PasswordHasher->hash($entity->get($formField)));

			if (!$entity->get($field)) {
				throw new RuntimeException('Empty field');
			}

			$entity->unsetProperty($formField);
			//$entity->set($formField, null);

			if ($this->_config['confirm']) {
				$formFieldRepeat = $this->_config['formFieldRepeat'];
				$entity->unsetProperty($formFieldRepeat);
			}
			if ($this->_config['current']) {
				$formFieldCurrent = $this->_config['formFieldCurrent'];
				$entity->unsetProperty($formFieldCurrent);
			}
		} else {
			// To help mitigate timing-based user enumeration attacks.
			$PasswordHasher->hash('');
		}
	}
public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $options) {
		$formField = $this->_config['formField'];
		$field = $this->_config['field'];

		$PasswordHasher = $this->_getPasswordHasher($this->_config['passwordHasher']);

		if ($entity->get($formField) !== null) {
			$entity->set($field, $PasswordHasher->hash($entity->get($formField)));

			if (!$entity->get($field)) {
				throw new RuntimeException('Empty field');
			}

			$entity->unsetProperty($formField);
			//$entity->set($formField, null);

			if ($this->_config['confirm']) {
				$formFieldRepeat = $this->_config['formFieldRepeat'];
				$entity->unsetProperty($formFieldRepeat);
			}
			if ($this->_config['current']) {
				$formFieldCurrent = $this->_config['formFieldCurrent'];
				$entity->unsetProperty($formFieldCurrent);
			}
		} else {
			// To help mitigate timing-based user enumeration attacks.
			$PasswordHasher->hash('');
		}
	}
public function beforeSave ( Event $ event , EntityInterface $ entity , ArrayObject $ options ) { $ formField = $ this -> _config [ 'formField' ] ; $ field = $ this -> _config [ 'field' ] ; $ PasswordHasher = $ this -> _getPasswordHasher ( $ this -> _config [ 'passwordHasher' ] ) ; if ( $ entity -> get ( $ formField ) !== null ) { $ entity -> set ( $ field , $ PasswordHasher -> hash ( $ entity -> get ( $ formField ) ) ) ; if ( ! $ entity -> get ( $ field ) ) { throw new RuntimeException ( 'Empty field' ) ; } $ entity -> unsetProperty ( $ formField ) ; //$entity->set($formField, null); if ( $ this -> _config [ 'confirm' ] ) { $ formFieldRepeat = $ this -> _config [ 'formFieldRepeat' ] ; $ entity -> unsetProperty ( $ formFieldRepeat ) ; } if ( $ this -> _config [ 'current' ] ) { $ formFieldCurrent = $ this -> _config [ 'formFieldCurrent' ] ; $ entity -> unsetProperty ( $ formFieldCurrent ) ; } } else { // To help mitigate timing-based user enumeration attacks. $ PasswordHasher -> hash ( '' ) ; } }
Hashing the password and whitelisting

@param \Cake\Event\Event $event
@param \Cake\Datasource\EntityInterface $entity
@param \ArrayObject $options
@throws \RuntimeException
@return void
Hashing the password and whitelisting