src/Model/Behavior/UserBehavior.php
public function sendNewPassword($email, $options = []) {
		if ($email instanceof EntityInterface) {
			$result = $email;
			$email = $result->get($this->_field('email'));
		} else {
			$result = $this->_table->find()
				->where([
					$this->_table->aliasField($this->_field('email')) => $email
				])
				->first();

			if (empty($result)) {
				throw new RecordNotFoundException(__d('user_tools', 'Invalid user'));
			}
		}

		$password = $this->generatePassword();
		$result->set([
			$this->_field('password') => $this->hashPassword($password),
			'clear_password' => $password
		], [
			'guard' => false
		]);

		$this->_table->save($result, ['validate' => false]);

		return $this->sendNewPasswordEmail($result, ['to' => $result->get($this->_field('email'))]);
	}
public function sendNewPassword($email, $options = []) {
		if ($email instanceof EntityInterface) {
			$result = $email;
			$email = $result->get($this->_field('email'));
		} else {
			$result = $this->_table->find()
				->where([
					$this->_table->aliasField($this->_field('email')) => $email
				])
				->first();

			if (empty($result)) {
				throw new RecordNotFoundException(__d('user_tools', 'Invalid user'));
			}
		}

		$password = $this->generatePassword();
		$result->set([
			$this->_field('password') => $this->hashPassword($password),
			'clear_password' => $password
		], [
			'guard' => false
		]);

		$this->_table->save($result, ['validate' => false]);

		return $this->sendNewPasswordEmail($result, ['to' => $result->get($this->_field('email'))]);
	}
public function sendNewPassword ( $ email , $ options = [ ] ) { if ( $ email instanceof EntityInterface ) { $ result = $ email ; $ email = $ result -> get ( $ this -> _field ( 'email' ) ) ; } else { $ result = $ this -> _table -> find ( ) -> where ( [ $ this -> _table -> aliasField ( $ this -> _field ( 'email' ) ) => $ email ] ) -> first ( ) ; if ( empty ( $ result ) ) { throw new RecordNotFoundException ( __d ( 'user_tools' , 'Invalid user' ) ) ; } } $ password = $ this -> generatePassword ( ) ; $ result -> set ( [ $ this -> _field ( 'password' ) => $ this -> hashPassword ( $ password ) , 'clear_password' => $ password ] , [ 'guard' => false ] ) ; $ this -> _table -> save ( $ result , [ 'validate' => false ] ) ; return $ this -> sendNewPasswordEmail ( $ result , [ 'to' => $ result -> get ( $ this -> _field ( 'email' ) ) ] ) ; }
Sends a new password to an user by email.

Note that this is *not* a recommended way to reset an user password. A much
more secure approach is to have the user manually enter a new password and
only send him an URL with a token.

@param string|EntityInterface $email The user entity or the email
@param array $options Optional options array, use it to pass config options.
@throws \Cake\Datasource\Exception\RecordNotFoundException
@return bool
Sends a new password to an user by email .