Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
 /**
  * @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());
 }