本文整理匯總了PHP中Nette\Security\Passwords::verify方法的典型用法代碼示例。如果您正苦於以下問題:PHP Passwords::verify方法的具體用法?PHP Passwords::verify怎麽用?PHP Passwords::verify使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Nette\Security\Passwords
的用法示例。
在下文中一共展示了Passwords::verify方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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);
}
示例2: authenticate
/**
* Performs an authentication.
*
* @param array $credentials
*
* @return Nette\Security\Identity
* @throws Nette\Security\AuthenticationException
*/
public function authenticate(array $credentials)
{
list($username, $password) = $credentials;
$user = $this->userRepository->findOneBy(["userName" => $username]);
$authExt = false;
foreach ($this->authDrivers as $authDriver) {
$authDriver->setUp($this->userRepository, $this->roleRepository, $this->userActivityRepository);
if ($authExt = $authDriver->authenticate($username, $password, $user)) {
if ($user) {
$user->authMethod = $authDriver->getName();
break;
} else {
$authExt = false;
}
}
}
if (!$authExt) {
if (!$user) {
throw new Security\AuthenticationException('Wrong username.', self::IDENTITY_NOT_FOUND);
} elseif (!Security\Passwords::verify($password, $this->userRepository->getPassword($user))) {
throw new Security\AuthenticationException('Wrong password.', self::INVALID_CREDENTIAL);
}
}
// update lastLogged
$user->lastLogged = new DateTime();
$this->userRepository->save($user);
$userActivity = new UserActivity();
$userActivity->userId = $user->id;
$userActivity->type = "login";
$this->userActivityRepository->save($userActivity);
return new Security\Identity($user->id, $user->roles, $user);
}
示例3: 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();
}
}
示例4: 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);
}
示例5: editUser
public function editUser($values, $user_id)
{
// $temp = $this->database->table('user')->where('email = ?', $values->email)->fetch();
$row = $this->database->table('user')->where('id', $user_id)->fetch();
if (!NS\Passwords::verify($values->oldPassword, $row->password)) {
// throw new NS\AuthenticationException('Špatné heslo.');
$check = 0;
} else {
if ($values->newPassword != NULL) {
$this->database->table('user')->where('id', $user_id)->update(['password' => Passwords::hash($values->newPassword)]);
}
if ($values->username != NULL) {
$this->database->table('user')->where('id', $user_id)->update(['username' => $values->username]);
}
$check = 1;
}
// $check = 0;
// if ((!$temp)) $check = 1;
// if ($check) {
// $this->database->table('user')->where('id', $user_id)->update([
// 'username' => $values->username,
// 'password' => Passwords::hash($values->newPassword),
// ]);
//
// /*$mail = new Message;
// $mail->setFrom('BrNOC bot <bot@brnoc.cz>')
// ->addTo($values->email)
// ->setSubject('Potvrzení příhlášení')
// ->setBody("Byl jsi přihlášen jako účastník BrNOCi 2015. \n \nBrNOC tým");*/
// }
return $check;
}
示例6: authenticate
/**
* Performs an authentication.
* @return Nette\Security\Identity
* @throws Nette\Security\AuthenticationException
*/
public function authenticate(array $credentials)
{
if (!Passwords::verify($credentials[1], $this->database->table('option')->get('password')->value)) {
throw new Nette\Security\AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);
}
return new Nette\Security\Identity(NULL, NULL, NULL);
}
示例7: onBeforeChange
public function onBeforeChange(Form $form, User $user)
{
$values = $form->getValues();
if (!Passwords::verify($values['currentPassword'], $user->password)) {
$this->flashMessage('Heslo nelze změnit, protože nesouhlasí
Vaše aktuální heslo.', 'warning');
$this->redirect('this');
}
}
示例8: updateUserPasswd
public function updateUserPasswd($curentPasswd, $newPasswd)
{
$row = $this->database->table(self::USER_TABLE_NAME)->where(self::USER_COLUMN_ID, $this->user->identity->id)->fetch();
if (Passwords::verify($curentPasswd, $row[self::USER_COLUMN_PASSWORD])) {
$this->database->table(self::USER_TABLE_NAME)->where(self::USER_COLUMN_ID, $this->user->identity->id)->update(array(self::USER_COLUMN_PASSWORD => Passwords::hash($newPasswd)));
return True;
} else {
return False;
}
}
示例9: authenticate
/**
* @param array $credentials
* @throws AuthenticationException
* @return Identity
*/
public function authenticate(array $credentials)
{
list($username, $password) = $credentials;
/** @var User $user */
$user = $this->userDao->findOneBy(['username' => $username]);
if (!$user || !Passwords::verify($password, $user->getPassword())) {
throw new AuthenticationException('Invalid username or password.', self::IDENTITY_NOT_FOUND);
}
return new Identity($user->getUserId(), NULL, $user->getLoginData());
}
示例10: 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;
}
示例11: 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;
}
示例12: authenticate
/**
* @param array $credentials
* @return \Nette\Security\Identity
* @throws \Nette\Security\AuthenticationException
*/
public function authenticate(array $credentials)
{
list($username, $password) = $credentials;
$user = $this->repository->findUserByName($username);
if (!is_null($user) && \Nette\Security\Passwords::verify($password, $user->getPassword())) {
$group = $this->repository->findGroupById($user->getGroupId());
return new \Nette\Security\Identity($user->id, $group->getName(), $user->getIdentity());
} else {
throw new \Nette\Security\AuthenticationException($this->t("forms.sign.errors.wrong-credentials"), self::IDENTITY_NOT_FOUND);
}
}
示例13: changePassword
public function changePassword($userId, $oldPassword, $newPassword)
{
$user = $this->get($userId);
if (Nette\Security\Passwords::verify($oldPassword, $user->passwordHash)) {
$user->passwordHash = Nette\Security\Passwords::hash($newPassword);
$this->em->flush();
return TRUE;
} else {
return FALSE;
}
}
示例14: authenticate
function authenticate(array $credentials)
{
list($username, $password) = $credentials;
$user = $this->user_service->getByLogin($username);
if (!$user) {
throw new AuthenticationException('Přihlášení se nezdařilo.');
}
if (!Passwords::verify($password, $user->password)) {
throw new AuthenticationException('Přihlášení se nezdařilo.');
}
return new Identity($user->id_user);
}
示例15: passwordChangeFormSucceeded
public function passwordChangeFormSucceeded(Form $form, $values)
{
$user = $this->userFacade->findOneById($this->user->getId());
if (!Passwords::verify($values->actualPassword, $user->hash)) {
$form->addError("Zadal si špatné aktuální heslo. Zkus to znovu!");
} else {
$user->changePassword($values->password);
$this->userFacade->save($user);
$form->getPresenter()->flashMessage("Tvoje heslo bylo úspěšně změněno", "alert-success");
$form->getPresenter()->redirect("this");
}
}