コード例 #1
0
ファイル: UserRepository.php プロジェクト: greeny/sandbox
 public function register(ArrayHash $data)
 {
     if ($this->findByNick($data->nick)) {
         throw new AuthenticationException("Uživatel '{$data->nick}' již existuje.");
     }
     /** @var User $user */
     $user = User::from($data);
     $user->salt = Strings::random(5, 'A-Za-z0-9');
     $user->password = PasswordHasher::hashPassword($user->nick, $user->password, $user->salt);
     $this->persist($user);
 }
コード例 #2
0
ファイル: Authenticator.php プロジェクト: greeny/sandbox
 /**
  * @param array $credentials
  * @throws \Nette\Security\AuthenticationException
  * @return IIdentity|void
  */
 function authenticate(array $credentials)
 {
     list($username, $password) = $credentials;
     if (!($user = $this->userRepository->findByNick($username))) {
         throw new AuthenticationException("Uživatel '{$username}' nenalezen.", self::IDENTITY_NOT_FOUND);
     }
     if (PasswordHasher::hashPassword($username, $password, $user->salt) !== $user->password) {
         throw new AuthenticationException("Špatné heslo.", self::INVALID_CREDENTIAL);
     }
     return new Identity($user->id, $user->role, $user->getData());
 }