Find User by username

@param string $username

@return User
510260
protected function getChoiceBySelection($selection)
    {
        preg_match('/^[^(]+\(([^\)]+)\)$/', $selection, $matches);
        if (count($matches) < 2) {
            return;
        }
        $username = $matches[1];
        foreach ($this->choices as $item) {
            if ($item->getUsername() === $username) {
                return $item;
            }
        }

        return;
    }
528430
public function findByName($playerName)
    {
        return $this->first(function (Player $player) use ($playerName) {
            return $player->name() === $playerName;
        });
    }
908541
private function findByUsername(string $username)
    {
        if ($this->userRepository instanceof UserRepositoryInterface) {
            return $this->userRepository->findByUsername($username);
        }

        return $this->userRepository->findOneBy(['username' => $username]);
    }
180880
public function getSingleUser(string $username): array
    {
        return $this->getApi()->request($this->getApi()->sprintf('/users/:username', $username));
    }
634630
public function loadUserByUsername($username)
    {

        $users = $this->userData->listEntries([$this->usernameField => $username], [$this->usernameField => '='], 0, 1);
        if (count($users) === 0) {
            throw new UsernameNotFoundException();
        }

        $user = $users[0];
        $roles = is_string($this->userRoleIdentifier) ? $this->loadUserRolesViaManyToMany($user) : $this->loadUserRolesViaData($user->get('id'));

        $userObj = new User($this->usernameField, $this->passwordField, $this->saltField, $user, $roles);
        return $userObj;
    }
1326768
public static function user($username)
    {
        $username = urlencode($username);

        return self::get(self::BASE_URL . '/json.php?username=' . $username);
    }
1029197
protected function _findUser($username, $password = null)
    {
        $userModel = $this->_config['userModel'];
        list($plugin, $model) = pluginSplit($userModel);
        $fields = $this->_config['fields'];

        $conditions = [$model . '.' . $fields['token'] => $username];
        if (!empty($this->_config['scope'])) {
            $conditions = array_merge($conditions, $this->_config['scope']);
        }
        $table = TableRegistry::get($userModel)->find('all');
        if ($this->_config['contain']) {
            $table = $table->contain($this->_config['contain']);
        }

        $result = $table
            ->where($conditions)
            ->hydrate(false)
            ->first();

        if (empty($result)) {
            return false;
        }

        unset($result[$fields['password']]);

        return $result;
    }
4131
public function getUsername($username)
    {
        if ($this->isValidUserDn($username)) {
            return $username;
        }
        $replacements = [
            $username,
            $this->config->getDomainName(),
        ];

        return preg_replace($this->params, $replacements, $this->bindFormat);
    }
1277269
public function find($username, array $data = [])
    {
        $response = $this->request->get(sprintf("users/%s", $username), $data);
        return new User($this->master, $response);
    }
194766
protected function findLdapUserDnByUsername($username)
    {
        $ldapClient = $this->getLdapClient();
        $options = $this->getUtils()->getOptions();

        $loginFilterString = '';
        if (!empty($options['userLoginFilter'])) {
            $loginFilterString = $this->convertToFilterFormat($options['userLoginFilter']);
        }

        $searchString = '(&(objectClass='.$options['userObjectClass'].')('.$options['userNameAttribute'].'='.$username.')'.$loginFilterString.')';
        $result = $ldapClient->search($searchString, null, LDAP\Client::SEARCH_SCOPE_SUB);
        $GLOBALS['log']->debug('LDAP: user search string: "' . $searchString . '"');

        foreach ($result as $item) {
            return $item["dn"];
        }
    }
1055846
public function username($username = null)
    {
        if (func_num_args() === 0) {
            return $this->_username;
        }
        $this->_username = $username ?: null;
        return $this;
    }
786624
public function UserProfile(string $username): Model\User\Profile
    {
        return $this->myanimelist->getUserProfile(
            new Request\User\UserProfileRequest($username)
        );
    }
1027732
private function findUserByUsernameOrThrowException($username)
    {
        $user = $this->userManager->findUserByUsername($username);

        if (!$user) {
            throw new InvalidArgumentException(sprintf('User identified by "%s" username does not exist.', $username));
        }

        return $user;
    }
778066
public static function findByUsername($username, $checkStatus = true)
    {
        return static::findOne(
            $checkStatus ?
                ['username' => $username, 'status' => self::STATUS_ACTIVE] :
                ['username' => $username]
        );
    }
834110
protected function createUniqueUsername( $username )
    {
        $originalName = $username;
        $existingUser = $this->userManager->findUserByUsername( $username );
        $suffix = 0;
        while ( $existingUser )
        {
            $suffix++;
            $username = $originalName . $suffix;
            $existingUser = $this->userManager->findUserByUsername( $username );
        }
        return $username;
    }
243545
def find_by_username(self, username):
        """"""
        data = (db.select(self.table).select('username', 'email', 'real_name',
                                             'password', 'bio', 'status', 'role', 'uid').
                condition('username', username).execute()
                )
        if data:
            return self.load(data[0], self.model)
665735
public function loadUserByUsername($username)
    {
        if (!$this->queryField || !$username) {
            return false;
        }

        $user = $this->documentModel->getRepository()->findOneBy(
            [
                $this->queryField => new \MongoRegex('/^'.preg_quote($username).'$/i')
            ]
        );

        return $user ? $user : false;
    }