Find user by username

@param string $searched_term
501044
public function findByUsernameContains($searched_term)
    {
        $qb = $this->createQueryBuilder('u');
        $qb instanceof QueryBuilder;

        $qb->add('where', $qb->expr()->like('u.username', $qb->expr()->lower(':searched_term')))
            ->setParameter('searched_term', $searched_term . '%');

        return $qb->getQuery()->getResult();
    }
210795
public function findByUserName($user_name): ?User
    {
        return DB::table('user')
            ->where('user_name', '=', $user_name)
            ->get()
            ->map(User::rowMapper())
            ->first();
    }
1078655
public function actionPassword($search, $password) {
    $user = User::findIdentityByUsernameOrEmail($search);
    if ($user === null) {
      $this->stdout(Yii::t('users', 'User is not found') . "\n", Console::FG_RED);
    } else {
      if ($user->resetPassword($password)) {
        $this->stdout(Yii::t('users', 'Password has been changed') . "\n", Console::FG_GREEN);
      } else {
        $this->stdout(Yii::t('users', 'Error occurred while changing password') . "\n", Console::FG_RED);
      }
    }
  }
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)
552044
@Override
    public List<User> searchUsers(String search) throws AuthenticationException {
        // Complete list of users
        String[] users = file_store.keySet().toArray(
                new String[file_store.size()]);
        List<User> found = new ArrayList<User>();

        // Look through the list for anyone who matches
        for (int i = 0; i < users.length; i++) {
            if (users[i].toLowerCase().contains(search.toLowerCase())) {
                found.add(getUser(users[i]));
            }
        }

        // Return the list
        return found;
    }
167646
def people_findByUsername(username):
    """"""
    method = 'flickr.people.findByUsername'
    data = _doget(method, username=username)
    user = User(data.rsp.user.id, username=data.rsp.user.username.text)
    return user
74150
public static function get_users_count($context, $search = '') {
        global $DB;

        list($sql, $params) = self::get_users_sql_and_params($context, $search, true);
        return $DB->count_records_sql($sql, $params);

    }
435520
public static function isBasedOnUsername($word, $username)
	{
		$word     = self::normalize($word);
		$username = self::normalize($username);

		$words   = array();
		$words[] = $username;
		$words[] = strrev($username);

		foreach ($words as $w)
		{
			if (empty($w))
			{
				continue;
			}

			if (empty($word))
			{
				continue;
			}

			if (strpos($w, $word) !== false)
			{
				return true;
			}
		}

		return false;
	}
338152
def list_users(ctx, search, uuid, active):
    """"""

    users = ctx.obj['db'].objectmodels['user']

    for found_user in users.find():
        if not search or (search and search in found_user.name):
            # TODO: Not 2.x compatible
            print(found_user.name, end=' ' if active or uuid else '\n')
            if uuid:
                print(found_user.uuid, end=' ' if active else '\n')
            if active:
                print(found_user.active)

    log("Done")
534217
function search_users( $q,  $count = 10 )
	{
		$params = array();
		$params['q'] = $q;
		$params['count'] = $count;
		return $this->oauth->get( 'search/suggestions/users',  $params );
	}
756156
public function findWorkspacesWithSelfRegistrationBySearch(User $user, $search)
    {
        $dql = '
            SELECT w
            FROM Claroline\CoreBundle\Entity\Workspace\Workspace w
            WHERE w.displayable = true
            AND w.selfRegistration = true
            AND (
                UPPER(w.name) LIKE :search
                OR UPPER(w.code) LIKE :search
            )
            AND w.id NOT IN (
                SELECT w2.id FROM Claroline\CoreBundle\Entity\Workspace\Workspace w2
                JOIN w2.roles r
                JOIN r.users u
                WHERE u.id = :userId
            )
            ORDER BY w.name
        ';
        $query = $this->_em->createQuery($dql);
        $query->setParameter('userId', $user->getId());
        $search = strtoupper($search);
        $query->setParameter('search', "%{$search}%");

        return $query->getResult();
    }
359155
def find_user(self, username=None, email=None):
        
        if username:
            return (
                self.get_session.query(self.user_model)
                .filter(func.lower(self.user_model.username) == func.lower(username))
                .first()
            )
        elif email:
            return (
                self.get_session.query(self.user_model).filter_by(email=email).first()
            )
1354366
public function findUserByUserName(string $username): User
    {
        foreach ($this->userRepositories as $repository) {
            $user = $repository->findByUsername($username);

            if ($user) {
                return $user;
            }
        }

        throw UserNotFound::withUsername($username);
    }
781749
public static function message_search_users($userid, $search, $limitfrom = 0, $limitnum = 0) {
        global $USER;

        $systemcontext = context_system::instance();

        $params = array(
            'userid' => $userid,
            'search' => $search,
            'limitfrom' => $limitfrom,
            'limitnum' => $limitnum
        );
        $params = self::validate_parameters(self::message_search_users_parameters(), $params);
        self::validate_context($systemcontext);

        if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) {
            throw new moodle_exception('You do not have permission to perform this action.');
        }

        list($contacts, $noncontacts) = \core_message\api::message_search_users(
            $params['userid'],
            $params['search'],
            $params['limitfrom'],
            $params['limitnum']);

        return array('contacts' => $contacts, 'noncontacts' => $noncontacts);
    }
956973
public function loadUserFollowers(string $username, int $count = 5000, int $cursor = -1, $cacheExpiry = null): stdClass
	{
		return $this->cachedRequest('followers/ids', [
			'screen_name' => $username,
			'count' => $count,
			'cursor' => $cursor,
		], $cacheExpiry);
	}
952625
protected function _query($username) {
		$table = TableRegistry::get($this->_config['userModel']);

		$columns = [];
		foreach ($this->_config['columns'] as $column) {
			$columns[] = [$table->aliasField($column) => $username];
		}
		$conditions = ['OR' => $columns];

		$options = [
			'conditions' => $conditions,
		];

		if (!empty($this->_config['scope'])) {
			$options['conditions'] = array_merge($options['conditions'], $this->_config['scope']);
		}
		if (!empty($this->_config['contain'])) {
			$options['contain'] = $this->_config['contain'];
		}

		$finder = $this->_config['finder'];
		if (is_array($finder)) {
			$options += current($finder);
			$finder = key($finder);
		}

		if (!isset($options['username'])) {
			$options['username'] = $username;
		}

		$query = $table->find($finder, $options);

		return $query;
	}
232994
public PaginatedList<User> listUsersBySearch(String terms) {
		PaginatedList<User> results = new PaginatedList<User>();
		Criteria criteria = this.dao.newCriteria(User.class);
		criteria.add(Restrictions.eq("deleted", false));
		
		Criteria count = this.dao.newCriteria(User.class).add(Restrictions.eq("deleted", false))
				.setProjection(Projections.countDistinct("id"));

		if (terms != null && !terms.isEmpty()) {
			Disjunction or = Restrictions.disjunction();
			or.add(Restrictions.like("name", "%" + terms + "%").ignoreCase());
			criteria.add(or);
			count.add(or);
		}

		results.setList(this.dao.findByCriteria(criteria, User.class));
		results.setTotal((Long) count.uniqueResult());
		return results;

	}