當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Security\Passwords類代碼示例

本文整理匯總了PHP中Nette\Security\Passwords的典型用法代碼示例。如果您正苦於以下問題:PHP Passwords類的具體用法?PHP Passwords怎麽用?PHP Passwords使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Passwords類的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: 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;
 }
開發者ID:norik16,項目名稱:TripMap,代碼行數:32,代碼來源:SettingsModel.php

示例3: registerFormSucceeded

 public function registerFormSucceeded($form, $values)
 {
     $hash = \Nette\Security\Passwords::hash($values['password']);
     $reguser = $this->database->table('users')->insert(array('username' => $values->username, 'password' => $hash, 'email' => $values->email));
     $this->flashMessage("Gratulujeme. Boli ste úspešne zaregistrovaný. Môžte sa prihlásiť do aplikácie.", 'success');
     $this->redirect('Sign:in');
 }
開發者ID:misnlog,項目名稱:2ndHandRadar,代碼行數:7,代碼來源:RegistrationPresenter.php

示例4: 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);
 }
開發者ID:vokracko,項目名稱:SimpleReader,代碼行數:12,代碼來源:UserManager.php

示例5: 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

示例6: add

 /**
  * Adds new user.
  * @param  string
  * @param  string
  * @return void
  */
 public function add($username, $password)
 {
     $user = new Entities\UserEntity();
     $user->setUsername($username);
     $user->setPassword(Passwords::hash($password));
     $this->userRepository->save($user);
 }
開發者ID:janlanger,項目名稱:nette-skeleton,代碼行數:13,代碼來源:UserManager.php

示例7: onSuccess

 public function onSuccess()
 {
     $v = $this->values;
     $user = $this->orm->users->getByEmail($v->email);
     if ($user && $user->registered) {
         $this->addError('duplicate');
         return;
     }
     if (!$user) {
         $user = new User();
         $user->email = $v->email;
         $this->orm->users->attach($user);
     }
     $user->gender = $v->gender;
     $user->setNames($v->name);
     $user->registered = TRUE;
     $plainHash = Passwords::hash($v->password);
     $user->password = $this->aes->encrypt($plainHash);
     $this->orm->flush();
     /** @var Auth $presenter */
     $presenter = $this->presenter;
     $presenter->user->login(new Identity($user->id));
     $this->iLog('auth.registration.password', ['entropy' => $this->entropy->compute($v->password, $user)]);
     $presenter->onLogin($user, TRUE);
 }
開發者ID:VasekPurchart,項目名稱:khanovaskola-v3,代碼行數:25,代碼來源:Registration.php

示例8: add

 /**
  * Adds new user.
  * @param  string
  * @param  string
  * @param  string
  * @return void
  * @throws DuplicateNameException
  */
 public function add($username, $email, $password)
 {
     try {
         $this->database->table(self::TABLE_NAME)->insert([self::COLUMN_NAME => $username, self::COLUMN_PASSWORD_HASH => Passwords::hash($password), self::COLUMN_EMAIL => $email]);
     } catch (Nette\Database\UniqueConstraintViolationException $e) {
         throw new DuplicateNameException();
     }
 }
開發者ID:nette,項目名稱:sandbox,代碼行數:16,代碼來源:UserManager.php

示例9: uprav

 /**
  * Upraví
  * @param int
  * @param string
  * @param string
  * @param string
  * @return int
  */
 public function uprav($id, $jmeno, $heslo, $role)
 {
     $u = array(self::COLUMN_NAME => $jmeno, self::COLUMN_ROLE => $role);
     if ($heslo) {
         $u[self::COLUMN_PASSWORD_HASH] = Passwords::hash($heslo);
     }
     return $this->database->table(self::TABLE_NAME)->where(self::COLUMN_ID, (int) $id)->update($u);
 }
開發者ID:myiyk,項目名稱:vote,代碼行數:16,代碼來源:UserManager.php

示例10: hashPassword

 public function hashPassword(ArrayHash $values)
 {
     if ($values->password) {
         $values->password = Passwords::hash($values->password);
     } else {
         unset($values->password);
     }
 }
開發者ID:04EO,項目名稱:TrainingTaskNette,代碼行數:8,代碼來源:UserFormFactory.php

示例11: add

 /**
  * @param \stdClass $user
  * @throws DuplicateNameException
  */
 public function add(\stdClass $user)
 {
     try {
         $this->userModel->add(['username' => $user->username, 'email' => $user->email, 'password' => Passwords::hash($user->password), 'first_name' => $user->firstName, 'last_name' => $user->lastName]);
     } catch (UniqueConstraintViolationException $e) {
         throw new DuplicateNameException();
     }
 }
開發者ID:janeczko,項目名稱:vpp,代碼行數:12,代碼來源:UserManager.php

示例12: update

 public function update($userID, $login, $password, $email)
 {
     try {
         $this->database->table(self::TABLE_NAME)->get($userID)->update(array(self::COLUMN_NAME => $login, self::COLUMN_PASSWORD_HASH => Passwords::hash($password), self::COLUMN_EMAIL => $email));
     } catch (Nette\Database\UniqueConstraintViolationException $e) {
         throw new DuplicateNameException();
     }
 }
開發者ID:sifuraz,項目名稱:-closed-myApp,代碼行數:8,代碼來源:UserManager.php

示例13: renderDefault

 /**
  * @param string|null $password
  */
 public function renderDefault($password = NULL)
 {
     if (!empty($password)) {
         $this->template->hash = \Nette\Security\Passwords::hash($password);
     }
     $this->setLayout(FALSE);
     $this->template->setFile(__DIR__ . '/template.latte');
 }
開發者ID:nella,項目名稱:simple-hash-authenticator,代碼行數:11,代碼來源:PasswordHashGeneratorPresenter.php

示例14: add

 /**
  * Adds new user.
  *
  * @param  string
  * @param  string
  */
 public function add($username, $password)
 {
     try {
         $this->connection->query('INSERT INTO [' . table(self::TABLE_NAME) . ']', array(self::COLUMN_NAME => $username, self::COLUMN_PASSWORD_HASH => Passwords::hash($password)));
     } catch (Exception $e) {
         throw new DuplicateNameException();
     }
 }
開發者ID:jan-martinek,項目名稱:peer-blender,代碼行數:14,代碼來源:UserRepository.php

示例15: add

 /**
  * Adds new user.
  * @param  string
  * @param  string
  * @param  string
  * @return void
  * @throws DuplicateNameException
  */
 public function add($username, $password, $role = 'guest')
 {
     try {
         $this->db->insert(self::TABLE_NAME, [self::COLUMN_NAME => $username, self::COLUMN_PASSWORD_HASH => Passwords::hash($password), self::COLUMN_ROLE => $role])->execute();
     } catch (Nette\Database\UniqueConstraintViolationException $e) {
         throw new DuplicateNameException();
     }
 }
開發者ID:svatekr,項目名稱:rsrs,代碼行數:16,代碼來源:UserManager.php


注:本文中的Nette\Security\Passwords類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。