当前位置: 首页>>代码示例>>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;未经允许,请勿转载。