public function forgotPassword() { $this->request->allowMethod('post'); $allUsers = $this->User->find('all', array('fields' => array('email', 'password', 'username'))); $emailRequest = $this->request->data['User']['email']; $usernameRequest = $this->request->data['User']['username']; $authCheck = $this->User->find('all', array('conditions' => array('email' => $emailRequest, 'username' => $usernameRequest))); $checkActive = 0; if (!empty($authCheck)) { $checkActive = $authCheck[0]['User']['active']; if ($checkActive == 1) { $passwordRandom = User::createRandomString(10); $passwordhash = AuthComponent::password($passwordRandom); $this->User->updateAll(array('password' => "'" . $passwordhash . "'"), array('email' => $emailRequest)); $Email = new CakeEmail('gmail'); $Email->emailFormat('html')->to($emailRequest)->subject('Reset Password')->send("Your new password is: {$passwordRandom}"); $this->Flash->success(__('Check your mail, please!')); return $this->redirect(array('action' => 'main')); } else { $this->Flash->error(__("your account don't exist. Please, try again.")); return $this->redirect(array('action' => 'main')); } } else { $this->Flash->error(__("your account don't exist. Please, try again.")); return $this->redirect(array('action' => 'main')); } }