src/Controller/Component/UserToolComponent.php
public function changePassword($options = []) {
		$options = Hash::merge($this->getConfig('changePassword'), $options);

		$entity = $this->UserTable->newEntity();
		$entity->accessible([
			'old_password',
			'password',
			'new_password',
			'confirm_password'
		], true);

		if ($this->_getRequest()->is(['post', 'put'])) {
			$entity = $this->UserTable->get($this->_getAuthObject()->user('id'));
			$entity = $this->UserTable->patchEntity($entity, $this->_getRequest()->data, [
				'validate' => 'changePassword'
			]);

			if ($this->UserTable->changePassword($entity)) {
				$this->_getRequest()->data = [];
				$entity = $this->UserTable->newEntity();
				$this->handleFlashAndRedirect('success', $options);
			} else {
				$this->handleFlashAndRedirect('error', $options);
			}
		}

		$this->_setViewVar('entity', $entity);
	}
public function changePassword($options = []) {
		$options = Hash::merge($this->getConfig('changePassword'), $options);

		$entity = $this->UserTable->newEntity();
		$entity->accessible([
			'old_password',
			'password',
			'new_password',
			'confirm_password'
		], true);

		if ($this->_getRequest()->is(['post', 'put'])) {
			$entity = $this->UserTable->get($this->_getAuthObject()->user('id'));
			$entity = $this->UserTable->patchEntity($entity, $this->_getRequest()->data, [
				'validate' => 'changePassword'
			]);

			if ($this->UserTable->changePassword($entity)) {
				$this->_getRequest()->data = [];
				$entity = $this->UserTable->newEntity();
				$this->handleFlashAndRedirect('success', $options);
			} else {
				$this->handleFlashAndRedirect('error', $options);
			}
		}

		$this->_setViewVar('entity', $entity);
	}
public function changePassword ( $ options = [ ] ) { $ options = Hash :: merge ( $ this -> getConfig ( 'changePassword' ) , $ options ) ; $ entity = $ this -> UserTable -> newEntity ( ) ; $ entity -> accessible ( [ 'old_password' , 'password' , 'new_password' , 'confirm_password' ] , true ) ; if ( $ this -> _getRequest ( ) -> is ( [ 'post' , 'put' ] ) ) { $ entity = $ this -> UserTable -> get ( $ this -> _getAuthObject ( ) -> user ( 'id' ) ) ; $ entity = $ this -> UserTable -> patchEntity ( $ entity , $ this -> _getRequest ( ) -> data , [ 'validate' => 'changePassword' ] ) ; if ( $ this -> UserTable -> changePassword ( $ entity ) ) { $ this -> _getRequest ( ) -> data = [ ] ; $ entity = $ this -> UserTable -> newEntity ( ) ; $ this -> handleFlashAndRedirect ( 'success' , $ options ) ; } else { $ this -> handleFlashAndRedirect ( 'error' , $ options ) ; } } $ this -> _setViewVar ( 'entity' , $ entity ) ; }
Let the logged in user change his password.

@param array $options Options
@return void
Let the logged in user change his password .