/** * doExecute * * @return mixed * @throws \Exception */ protected function doExecute() { $username = $this->input->getUsername('username'); $token = $this->input->getUsername('token'); $password = $this->input->getString('password'); $password2 = $this->input->getString('password2'); try { if (!trim($password)) { throw new ValidFailException(Translator::translate('windwalker.user.password.not.entered')); } if ($password != $password2) { throw new ValidFailException(Translator::translate('windwalker.user.password.not.match')); } $user = User::get(array('username' => $username)); if ($user->isNull()) { throw new ValidFailException(Translator::translate('windwalker.user.not.found')); } $passwordObject = new Password(); if (!$passwordObject->verify($token, $user->reset_token)) { throw new ValidFailException(Translator::translate('windwalker.user.invalid.token')); } $user->password = $passwordObject->create($password); $user->reset_token = ''; $user->last_reset = ''; User::save($user); } catch (ValidFailException $e) { $this->setRedirect($this->router->http('reset', array('task' => 'reset', 'username' => $username, 'token' => $token)), $e->getMessage(), Bootstrap::MSG_DANGER); return false; } $this->setRedirect($this->router->http('reset', array('task' => 'complete'))); return true; }
/** * confirm * * @return boolean */ protected function confirm() { $token = $this->input->get('token'); $username = $this->input->getUsername('username'); $user = User::get(array('username' => $username)); if ($user->isNull()) { $this->setRedirect($this->router->http('forgot', array('task' => 'confirm', 'token' => $token)), Translator::translate('windwalker.user.no.user.found')); return false; } // Check token $password = new Password(); if (!$password->verify($token, $user->reset_token)) { $this->setRedirect($this->router->http('forgot', array('task' => 'confirm')), Translator::translate('windwalker.user.invalid.token')); return false; } $this->setRedirect($this->router->http('reset', array('username' => $username, 'token' => $token))); return true; }
/** * doSave * * @param DataInterface $data * * @return bool * * @throws ValidateFailException */ protected function doSave(DataInterface $data) { $user = User::get(array('email' => $this->data['email'])); if ($user->isNull()) { throw new ValidateFailException(Translator::translate($this->langPrefix . 'user.not.found')); } // Check token $password = new Password(); if (!$password->verify($this->data['token'], $user->reset_token)) { throw new ValidateFailException('Invalid Token'); } return true; }
/** * doSave * * @param DataInterface $data * * @return bool * * @throws ValidateFailException */ protected function doSave(DataInterface $data) { if (!trim($this->data['password'])) { throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.password.not.entered')); } if ($this->data['password'] != $this->data['password2']) { throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.password.not.match')); } /** @var UserRecord $user */ $user = User::get(array('email' => $this->data['email'])); if ($user->isNull()) { throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.user.not.found')); } $passwordObject = new Password(); if (!$passwordObject->verify($this->data['token'], $user->reset_token)) { throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.invalid.token')); } $user->password = $passwordObject->create($this->data['password']); $user->reset_token = ''; $user->last_reset = ''; User::save($user); }
/** * Method to test create(). * * @return void * * @covers Windwalker\Crypt\Password::create * @covers Windwalker\Crypt\Password::verify */ public function testCreateBlowfish() { $this->instance->setType(Password::BLOWFISH); $pass = $this->instance->create('windwalker'); $prefix = version_compare(PHP_VERSION, '5.3.7') >= 0 ? '$2y$' : '$2a$'; $this->assertEquals(crypt('windwalker', $prefix . '10$sakurasakurasakurasaku$'), $pass); $this->assertTrue($this->instance->verify('windwalker', $pass)); // Use default $password = new Password(); $this->assertTrue($password->verify('windwalker', $password->create('windwalker'))); }