本文整理汇总了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();
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}