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); }
/** * @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()); }