/** * Validates given username. * * @param string $userName * * @return string Validated username (trimmed and filtered) * @throws Exception If username is not valid */ public function validateUserName($userName) { $userName = trim($userName); // check for valid characters: if (strlen($userName) == 0 || !preg_match('/^[a-zA-Z0-9\\-_ ]+$/', $userName)) { throw new Exception($this->options->getOption('message_error_1', 'Only letters, number, spaces, hyphens and underscores are allowed')); } // filter the new username: if ($this->options->isOptionEnabled('filter_bad_words')) { WiseChatContainer::load('rendering/filters/pre/WiseChatFilter'); $userName = WiseChatFilter::filter($userName); } // check if the new username is already occupied: $occupiedException = new Exception($this->options->getOption('message_error_2', 'This name is already occupied')); $prefix = $this->options->getOption('user_name_prefix', 'Anonymous'); if ($this->getUserNameOrEmptyString() == $userName || $this->usersDAO->getWpUserByDisplayName($userName) !== null || $this->usersDAO->getWpUserByLogin($userName) !== null || $this->channelUsersDAO->isUserNameOccupied($userName, $this->userSessionDAO->getSessionId()) || preg_match("/^{$prefix}/", $userName) || $userName == $this->getSystemUser()->getName()) { throw $occupiedException; } return $userName; }