当前位置: 首页>>代码示例>>PHP>>正文


PHP Passwords::needsRehash方法代码示例

本文整理汇总了PHP中Nette\Security\Passwords::needsRehash方法的典型用法代码示例。如果您正苦于以下问题:PHP Passwords::needsRehash方法的具体用法?PHP Passwords::needsRehash怎么用?PHP Passwords::needsRehash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Nette\Security\Passwords的用法示例。


在下文中一共展示了Passwords::needsRehash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: authenticate

 /**
  * Performs an authentication against e.g. database.
  * and returns IIdentity on success or throws AuthenticationException
  * @var array $credentials
  * @return Nette\Security\IIdentity
  * @throws Nette\Security\AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($username, $password) = $credentials;
     if (is_null($password)) {
         $user = $this->manager->getItem($username);
     } else {
         $user = $this->manager->getUserByUsername($username);
         if (is_null($user->password)) {
             throw new Trejjam\Authorization\User\AuthenticatorException('User has not have defined password.', Trejjam\Authorization\User\AuthenticatorException::NOT_DEFINED_PASSWORD);
         } else {
             if (!Nette\Security\Passwords::verify($password, $user->password)) {
                 throw new Trejjam\Authorization\User\AuthenticatorException('The password is incorrect.', Trejjam\Authorization\User\AuthenticatorException::INVALID_CREDENTIAL);
             } else {
                 if (Nette\Security\Passwords::needsRehash($user->password)) {
                     $this->manager->changePassword($user, $password);
                 }
             }
         }
     }
     if ($this->manager->isEnableLogin($user)) {
         $baseUserArr = (array) $this->manager->getUserInfo($user);
         $baseUserArr["login_time"] = new Nette\Utils\DateTime();
         $role = $this->acl->getUserRoles($user);
         return new Identity($user->id, $role, $baseUserArr);
     } else {
         //this may not happen
         throw new Trejjam\Authorization\User\AuthenticatorException();
     }
 }
开发者ID:trejjam,项目名称:authorization,代码行数:36,代码来源:Authenticator.php

示例2: authenticate

 /**
  * Performs an authentication.
  * @param array $credentials (string $username, string $password)
  * @return Nette\Security\Identity
  * @throws Nette\Security\AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($username, $password) = $credentials;
     $row = $this->database->table('user')->where('username', $username)->fetch();
     if (!$row) {
         throw new Security\AuthenticationException('Uživatel s tímto jménem neexistuje.', self::IDENTITY_NOT_FOUND);
     } elseif (!Security\Passwords::verify($password, $row->password)) {
         throw new Security\AuthenticationException('Nesprávné heslo.', self::INVALID_CREDENTIAL);
     } elseif (!$row->active) {
         throw new Security\AuthenticationException('Účet není aktivovaný.', self::NOT_APPROVED);
     } elseif (Security\Passwords::needsRehash($row->password)) {
         $row->update(array('password' => Security\Passwords::hash($password)));
     }
     $arr = $row->toArray();
     unset($arr['password']);
     $roles = $row->related('privilege')->fetch()->toArray();
     unset($roles['user_id']);
     //adds privileges
     array_walk($roles, function (&$value, $key) use(&$roles) {
         if ($value != NULL) {
             $value = $key . ' - ' . $value;
         }
     });
     return new Security\Identity($row->id, $roles, $arr);
 }
开发者ID:patrickkusebauch,项目名称:27skauti,代码行数:31,代码来源:Authenticator.php

示例3: authenticate

 /**
  * @param array $credentials
  * @return Identity
  * @throws AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($email, $password) = $credentials;
     $user = $this->orm->users->getByEmail($email);
     if (!$user) {
         throw new AuthenticationException('auth.flash.wrongUsername', self::IDENTITY_NOT_FOUND);
     }
     if (!$user->password) {
         throw new AuthenticationException('auth.flash.notSet', self::PASSWORD_NOT_SET);
     }
     $plainHash = $this->aes->decrypt($user->password);
     if (strpos($user->password, 'old-password;') === 0) {
         $this->authOldPassword($password, $user);
     } else {
         if (!Passwords::verify($password, $plainHash)) {
             throw new AuthenticationException('auth.flash.wrongPassword', self::INVALID_CREDENTIAL);
         }
     }
     if (Passwords::needsRehash($plainHash)) {
         $plainHash = Passwords::hash($password);
         $user->password = $this->aes->encrypt($plainHash);
         $this->orm->flush();
     }
     return new Identity($user->id);
 }
开发者ID:VasekPurchart,项目名称:khanovaskola-v3,代码行数:30,代码来源:Authenticator.php

示例4: verifyPassword

 /**
  * Compare $password to origin
  * @param $password
  * @return bool
  */
 public function verifyPassword($password)
 {
     if (Passwords::verify($password, $this->password)) {
         if (Passwords::needsRehash($this->password)) {
             $this->setPassword($password);
         }
         return TRUE;
     }
     return FALSE;
 }
开发者ID:studna,项目名称:common,代码行数:15,代码来源:Password.php

示例5: checkInstallationPassword

 /**
  * Funkce kontrolující, zda zadané heslo odpovídá hodnotě uložené v configu
  * @param string $password
  * @return bool
  */
 public function checkInstallationPassword($password)
 {
     $passwordHash = $this->data['parameters']['install']['password'];
     if (Passwords::verify($password, $passwordHash)) {
         if (Passwords::needsRehash($password)) {
             $this->saveInstallationPassword($password);
         }
         return true;
     }
     return false;
 }
开发者ID:kizi,项目名称:easyminer-easyminercenter,代码行数:16,代码来源:ConfigManager.php

示例6: authenticate

 /**
  * @param array $credentials
  * @return null|User
  * @throws AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($email, $password) = $credentials;
     $user = $this->users->findOneBy(['email' => $email]);
     if (!$user) {
         throw new AuthenticationException('Invalid credentials.', self::IDENTITY_NOT_FOUND);
     } elseif (!Passwords::verify($password, $user->password)) {
         throw new AuthenticationException('Invalid credentials.', self::INVALID_CREDENTIAL);
     } elseif (Passwords::needsRehash($user->password)) {
         $user->setPassword($password);
         $this->em->flush();
     }
     return $user;
 }
开发者ID:wodcz,项目名称:sandbox,代码行数:19,代码来源:Authenticator.php

示例7: authenticate

 /**
  * Performs an authentication.
  * @return Nette\Security\Identity
  * @throws Nette\Security\AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($username, $password) = $credentials;
     $user = $this->usersFacade->findByName($username);
     if ($user == null) {
         throw new Nette\Security\AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND);
     } elseif (!Passwords::verify($password, $user->getPassword())) {
         throw new Nette\Security\AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);
     } elseif (Passwords::needsRehash($user->getPassword())) {
         $this->usersFacade->update(array('password' => Passwords::hash($password)));
     }
     $arr = array($user->getUsername(), $user->getEmail(), $user->getDate());
     return new Nette\Security\Identity($user->getId(), $user->getRole(), $arr);
 }
开发者ID:04EO,项目名称:hup-nette,代码行数:19,代码来源:UserManager.php

示例8: authenticate

 /**
  * Performs an authentication
  *
  * Partly taken from Nette Sandbox tutorial
  *
  * @return Nette\Security\Identity
  * @throws Nette\Security\AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($email, $password) = $credentials;
     $user = $this->database->table('user')->where('email', $email)->fetch();
     if (!$user) {
         throw new Nette\Security\AuthenticationException('User not found.', self::IDENTITY_NOT_FOUND);
     } elseif (!Passwords::verify($password, $user['password'])) {
         throw new Nette\Security\AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);
     } elseif (Passwords::needsRehash($user['password'])) {
         // from Nette Sandbox
         $user->update(array('password' => Passwords::hash($password)));
     }
     return new Nette\Security\Identity($user['id'], 'admin', array('name' => $user->name, 'email' => $user->email));
 }
开发者ID:rotten77,项目名称:asdf,代码行数:22,代码来源:Auth.php

示例9: authenticate

 /**
  * Performs an authentication.
  * @return Nette\Security\Identity
  * @throws Nette\Security\AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($username, $password) = $credentials;
     $user = $this->findUser($username);
     if (!$user) {
         throw new Nette\Security\AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND);
     } elseif (!strcmp($password, $user[self::COLUMN_PASSWORD_HASH])) {
         throw new Nette\Security\AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);
     } elseif (Passwords::needsRehash($user[self::COLUMN_PASSWORD_HASH])) {
         $user->update(array(self::COLUMN_PASSWORD_HASH => Passwords::hash($password)));
     }
     $arr = $user->toArray();
     unset($arr[self::COLUMN_PASSWORD_HASH]);
     return new Nette\Security\Identity($user[self::COLUMN_ID], $user[self::COLUMN_ROLE], $arr);
 }
开发者ID:Thoronir42,项目名称:G-archive,代码行数:20,代码来源:UserManager.php

示例10: authenticate

 function authenticate(array $credentials)
 {
     list($email, $password) = $credentials;
     /** @var User $user */
     $user = $this->em->getRepository(User::class)->findOneBy(array('email' => $email));
     if (!$user) {
         throw new AuthenticationException("User with e-mail {$email} not found.", self::IDENTITY_NOT_FOUND);
     } elseif (!Passwords::verify($password, $user->getPassword())) {
         throw new AuthenticationException('Incorrect password.', self::INVALID_CREDENTIAL);
     } elseif (Passwords::needsRehash($user->getPassword())) {
         $user->setPassword(Passwords::hash($password));
     }
     $arr = array('email' => $user->getEmail(), 'id' => $user->getId(), 'role' => $user->getRole());
     return new Identity($arr['id'], $arr['role'], $arr);
 }
开发者ID:vitush93,项目名称:kryo,代码行数:15,代码来源:Auth.php

示例11: authenticate

 /**
  * Performs an authentication.
  * @return Nette\Security\Identity
  * @throws Nette\Security\AuthenticationException
  */
 public function authenticate(array $qqscredentials)
 {
     list($sUsername, $sPassword) = $qqscredentials;
     $oRow = $this->oDatabase->table(self::TABLE_NAME)->where(self::COLUMN_NAME, $sUsername)->fetch();
     if (!$oRow) {
         throw new Nette\Security\AuthenticationException('Neplatné heslo.', self::IDENTITY_NOT_FOUND);
     } elseif (!Passwords::verify($sPassword, $oRow[self::COLUMN_PASSWORD_HASH])) {
         throw new Nette\Security\AuthenticationException('Neplatné heslo.', self::INVALID_CREDENTIAL);
     } elseif (Passwords::needsRehash($oRow[self::COLUMN_PASSWORD_HASH])) {
         $oRow->update(array(self::COLUMN_PASSWORD_HASH => Passwords::hash($sPassword)));
     }
     $qoData = $oRow->toArray();
     unset($qoData[self::COLUMN_PASSWORD_HASH]);
     return new Nette\Security\Identity($oRow[self::COLUMN_ID], $this->oDatabase->table(self::TABLE_ROLE_NAME)->select(self::COLL_NAME)->get($oRow[self::COLUMN_TYP])[self::COLL_NAME], $qoData);
 }
开发者ID:GreenOceanCZ,项目名称:kelio-test,代码行数:20,代码来源:UserManager.php

示例12: authenticate

 /**
  * Performs an authentication against e.g. database.
  * and returns IIdentity on success or throws AuthenticationException
  * @return IIdentity
  * @throws AuthenticationException
  */
 function authenticate(array $credentials)
 {
     list($username, $password) = $credentials;
     foreach ($this->userlist as $name => $pass) {
         if (strcasecmp($name, $username) === 0) {
             $isNoHashed = Passwords::needsRehash($pass);
             if ($isNoHashed and (string) $pass === (string) $password or !$isNoHashed and Passwords::verify($password, $pass)) {
                 return new Identity($name, isset($this->usersRoles[$name]) ? $this->usersRoles[$name] : NULL);
             } else {
                 throw new AuthenticationException('Invalid password.', self::INVALID_CREDENTIAL);
             }
         }
     }
     throw new AuthenticationException("User '{$username}' not found.", self::IDENTITY_NOT_FOUND);
 }
开发者ID:pipaslot,项目名称:security,代码行数:21,代码来源:SimpleHashedAuthenticator.php

示例13: authenticate

 /**
  * Performs an authentication.
  * @return Nette\Security\Identity
  * @throws Nette\Security\AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($username, $password) = $credentials;
     $user = $this->userRepository->findOneBy(array('username' => $username));
     /** @var \App\Model\Entities\UserEntity $user */
     if (!$user) {
         throw new Nette\Security\AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND);
     } elseif (Passwords::verify($password, $user->password)) {
         throw new Nette\Security\AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);
     } elseif (Passwords::needsRehash($user->password)) {
         $user->password = Passwords::hash($password);
         $this->userRepository->save($user);
     }
     return $user;
 }
开发者ID:janlanger,项目名称:nette-skeleton,代码行数:20,代码来源:UserManager.php

示例14: authenticate

 /**
  * @throws Nette\Security\AuthenticationException
  * @return Nette\Security\Identity
  */
 public function authenticate(array $credentials)
 {
     list($email, $password) = $credentials;
     $user = $this->userRepository->getByEmail($email);
     if (!$user) {
         throw new Nette\Security\AuthenticationException($this->translator->translate('locale.sign.incorrect_email'), self::IDENTITY_NOT_FOUND);
     } elseif (!$user->isAuthenticated) {
         throw new Nette\Security\AuthenticationException($this->translator->translate('locale.sign.authentication_waiting'), self::NOT_APPROVED);
     } elseif (!Passwords::verify($password . $user->salt, $user->password)) {
         throw new Nette\Security\AuthenticationException($this->translator->translate('locale.sign.incorrect_password'), self::INVALID_CREDENTIAL);
     } elseif (Passwords::needsRehash($user->password)) {
         $this->userRepository->updatePassword($user, $user->password);
     }
     return $this->updateIdentity($user);
 }
开发者ID:CSHH,项目名称:website,代码行数:19,代码来源:Authenticator.php

示例15: authenticate

 /**
  * Performs an authentication.
  * @param array $credentials
  * @return Nette\Security\Identity
  * @throws Nette\Security\AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($email, $password) = $credentials;
     $row = $this->findByEmail($email);
     if (!$row) {
         throw new Nette\Security\AuthenticationException(sprintf('Unknown user', $email), self::IDENTITY_NOT_FOUND);
     } elseif (!Passwords::verify($password, $row['password'])) {
         throw new Nette\Security\AuthenticationException('Invalid password', self::INVALID_CREDENTIAL);
     } elseif (Passwords::needsRehash($row['password'])) {
         $row->update(['password' => Passwords::hash($password)]);
     }
     $arr = $row->toArray();
     unset($arr['password']);
     return new Nette\Security\Identity($row['id'], null, $arr);
 }
开发者ID:martinmayer,项目名称:notejam,代码行数:21,代码来源:UserManager.php


注:本文中的Nette\Security\Passwords::needsRehash方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。