public function encrypt($password, $salt = null) { if ($this->algorithm != 'none') { return Hash::compute(self::$algorithms[$this->algorithm], $password . $salt); } return $password; }
/** * Set the hash algorithm for HMAC authentication * * @param string $hash * @return BlockCipher * @throws Exception\InvalidArgumentException */ public function setHashAlgorithm($hash) { if (!Hash::isSupported($hash)) { throw new Exception\InvalidArgumentException("The specified hash algorithm '{$hash}' is not supported by Zend\\Crypt\\Hash"); } $this->hash = $hash; return $this; }
public function modifierAction() { $routeId = (int) $this->params()->fromRoute('id'); $id = $routeId == 0 ? $this->identity()->getId() : $routeId; /** @var Utilisateur $utilisateur */ $utilisateur = $this->identity(); if ($utilisateur->getId() != $id && $utilisateur->getRole() != Utilisateur::ROLE_ADMINISTRATEUR) { $this->flashMessenger()->addErrorMessage('L\'utilisateur n\'existe pas.'); return $this->redirect()->toRoute('accueil'); } /** @var EntityManager $em */ $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); /** @var Utilisateur $utilisateur */ $utilisateur = $em->getRepository('Application\\Entity\\Utilisateur')->find($id); if (is_null($utilisateur)) { $this->flashMessenger()->addErrorMessage('L\'utilisateur n\'existe pas.'); return $this->redirect()->toRoute('accueil'); } $form = new UtilisateurForm($em); $form->bind($utilisateur); /** @var Request $request */ $request = $this->getRequest(); if ($request->isPost()) { $post = $request->getPost(); $unchanged = false; if ($post['password'] == '' && $post['passwordConfirmation'] == '') { $unchanged = true; } $form->setData($post); if ($form->isValid()) { if (!$unchanged) { $utilisateur->setEncryptedPassword(Hash::compute('sha256', $utilisateur->getPassword())); } $em->flush(); $this->flashMessenger()->addSuccessMessage('L\'utilisateur a bien été modifié.'); $subject = 'Votre compte a été mis à jour'; $viewMessage = new ViewModel(); $viewMessage->setTemplate('mail/utilisateur-maj')->setVariables(array('user' => $utilisateur))->setTerminal(true); $viewRender = $this->getServiceLocator()->get('ViewRenderer'); $message = $viewRender->render($viewMessage); $to = $utilisateur->getEmail(); $mailer = new Mailer($this->getServiceLocator()); $mailer->sendMail($subject, $message, $to); return $this->redirect()->toRoute('utilisateur', array('action' => 'detail', 'id' => $id)); } } $view = new ViewModel(); return $view->setVariables(array('utilisateur' => $utilisateur, 'id' => $routeId, 'form' => $form)); }
public function testBinaryOutput() { $hash = Hash::compute('sha1', 'test', Hash::OUTPUT_BINARY); $this->assertEquals('qUqP5cyxm6YcTAhz05Hph5gvu9M=', base64_encode($hash)); }
public function reinitialisationMdpAction() { $this->layout('layout/connexion'); $token = $this->params()->fromRoute('token', false); if (!$token) { return $this->redirect()->toRoute('unauthorized'); } /** @var EntityManager $em */ $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $form = new ResetPasswordForm($em); /** @var Request $request */ $request = $this->getRequest(); if ($request->isPost()) { $form->setData($request->getPost()); if ($form->isValid()) { /** @var Utilisateur $utilisateur */ $utilisateur = $em->getRepository('Application\\Entity\\Utilisateur')->findOneBy(array('email' => $form->getData()['email'])); if (is_null($utilisateur) || $utilisateur->getToken() != $token) { $this->flashMessenger()->addErrorMessage('L\'adresse email ou le token est incorrect.'); } else { $utilisateur->setEncryptedPassword(Hash::compute('sha256', $form->getData()['password'])); $utilisateur->setToken(null); $em->persist($utilisateur); $em->flush(); $subject = 'Réinitialisation de votre mot de passe'; $viewMessage = new ViewModel(); $viewMessage->setTemplate('mail/utilisateur-maj-mdp')->setVariables(array('utilisateur' => $utilisateur))->setTerminal(true); $viewRender = $this->getServiceLocator()->get('ViewRenderer'); $message = $viewRender->render($viewMessage); $to = $utilisateur->getEmail(); $mailer = new Mailer($this->getServiceLocator()); $mailer->sendMail($subject, $message, $to); $this->flashMessenger()->addSuccessMessage('Votre mot de passe a bien été modifié.'); return $this->redirect()->toRoute('connexion'); } } } $view = new ViewModel(); return $view->setVariables(array('form' => $form)); }
/** * (non-PHPdoc) * @see \InoOicServer\Session\Hash\Generator\GeneratorInterface::generateRefreshToken() */ public function generateRefreshToken(AccessToken $accessToken, Client $client) { $data = $accessToken->getToken() . $client->getId() . microtime(true) . 'refresh_token'; return Hash::compute('sha1', $data); }
/** * Revokes all access tokens for a give refresh token * @param $value refresh token value * @param bool $is_hashed * @return bool|void */ public function clearAccessTokensForRefreshToken($value, $is_hashed = false) { $hashed_value = !$is_hashed ? Hash::compute('sha256', $value) : $value; $res = false; $cache_service = $this->cache_service; $this->tx_service->transaction(function () use($hashed_value, &$res, &$cache_service) { $refresh_token_db = DBRefreshToken::where('value', '=', $hashed_value)->first(); if (!is_null($refresh_token_db)) { $access_tokens_db = DBAccessToken::where('refresh_token_id', '=', $refresh_token_db->id)->get(); if (!count($access_tokens_db)) { $res = true; } foreach ($access_tokens_db as $access_token_db) { $res = $cache_service->delete($access_token_db->value); $client = $access_token_db->client()->first(); $res = $cache_service->deleteMemberSet($client->client_id . TokenService::ClientAccessTokenPrefixList, $access_token_db->value); $access_token_db->delete(); } } }); return $res; }
public function testTransformHex() { $this->assertEquals(Hash::compute(self::ALGORITHM, self::VALUE_HEX), $this->transformer->transform(self::VALUE_HEX)); }
/** * Verify if a password is correct against a hash value * * @param string $password * @param string $hash * @throws Exception\RuntimeException when the hash is unable to be processed * @return bool */ public function verify($password, $hash) { return parent::verify(Hash::compute('sha256', $password), $hash); }
/** * @param string $value * @return string */ public function transform($value) { return Hash::compute($this->getAlgorithm(), $value, $this->getBinary()); }
public function compute($data) { return Hash::compute($this->algorithm, $data); }