Find a non existing User name

@return string A not used name

@throws \Exception Possible endless loop
428272
private function findNonExistingUserName()
    {
        $userManager = $this->getUserManager();
        for ( $i = 0; $i < 20; $i++ )
        {
            $username = substr(uniqid('User#', true), 0, 15);
            if ( !$userManager->checkUserExistenceByUsername( $username ) )
            {
                return $username;
            }
        }

        throw new \Exception( 'Possible endless loop when attempting to find a new name for User.' );
    }
817882
protected function getUser()
    {
        trigger_error('DrupalSubContextBase::getUser() is deprecated. Use RawDrupalContext::getUserManager()->getCurrentUser() instead.', E_USER_DEPRECATED);

        $user = $this->getUserManager()->getCurrentUser();

        if (empty($user)) {
            throw new \Exception('No user is logged in.');
        }

        return $user;
    }
991280
public function findUser() {
        $model = ClassRegistry::init($this->usersModel);
        $id = trim($this->in('User ID:'));

        if (!$id) {
            $this->out('<error>Invalid ID, please try again</error>');
            return $this->findUser();
        }

        $result = $model->find('first', array(
            'conditions' => array($model->alias . '.' . $model->primaryKey => $id),
            'recursive' => -1
        ));

        if (!$result) {
            $this->out('<error>User does not exist, please try again</error>');
            return $this->findUser();
        }

        $this->user = $result;

        return $id;
    }
1024112
public function getUsername()
    {
        if (!$this->hasEnabledUsername()) {
            return null;
        }
        $usernameClass = $this->usernameClass;
        $noInit = $usernameClass::buildNoInitModel();
        /* @var $noInit Username */
        return $this->hasOne($usernameClass, [$noInit->createdByAttribute => $this->guidAttribute]);
    }
652669
public static function userExists($username)
	{
		if ( ! is_array( self::$auth ) ) throw new Exception( 'Authentication not initialized' );
		return ( isset( self::$auth['users'][ $username ] ) );
	}
556831
public function getName()
    {
        $name = false;

        // - we are on admin
        $sm = $this->themeLocator->getServiceLocator();

        // get registered PermissionsManager service and retrieve plugin
        $permissionsManager = $sm->get('yimaAuthorize.AuthServiceManager');

        /** @var $permission \yimaAdminor\Auth\AuthService */
        $permission = $permissionsManager->get('yima_adminor');
        if (!$permission->identity()->hasAuthenticated())
            // user not authorized to adminor
            return false;

        $config = $sm->get('config');
        if (isset($config['yima_adminor']) && is_array($config['yima_adminor'])) {

            $name = (isset($config['yima_adminor']['default_theme']))
                ? $config['yima_adminor']['default_theme']
                : false;
        }

        return $name;
    }
353122
public function getUsername()
    {
        if (isset($this->_username)) {
            return $this->_username;
        } elseif (($identity = Yii::$app->user->identity) !== null) {
            if ($identity->hasProperty('username')) {
                $this->_username = $identity->username;
            } else {
                $this->_username = $identity->getId();
            }

            return $this->_username;
        }
        throw new InvalidConfigException('Unable to determine username');
    }
108134
public function getUsername()
    {
        $username = null;
        $link = $this->getLink();

        if (!empty($link)) {
            $username = substr($link, strrpos($link, '/') + 1);
        }

        return $username;
    }
1328909
public function getUserSession() {
		if (isset($_SESSION['user_'.$this->usernameKey])) {
			$arrUser = array();
			foreach ($_SESSION as $strKey => $strValue)
				if (substr($strKey, 0, 4) == 'user_')
					$arrUser[substr($strKey, 4)] = $strValue;
			return $arrUser;
		}

		return false;
	}
888023
protected function _getUserId(): ?string
    {
        $userId = null;
        $callback = $this->config('userIdCallback');
        if (is_callable($callback)) {
            $userId = $callback();
        }

        return $userId;
    }
1338928
public function getUserByName($username)
    {
        return $this->getUsers()->then(function (array $users) use ($username) {
            foreach ($users as $user) {
                if ($user->getUsername() === $username) {
                    return $user;
                }
            }

            throw new UserNotFoundException("The user \"$username\" does not exist.");
        });
    }
573578
function user_exists($username) {
        $extusername = core_text::convert($username, 'utf-8', $this->config->ldapencoding);

        // Returns true if given username exists on ldap
        $users = $this->ldap_get_userlist('('.$this->config->user_attribute.'='.ldap_filter_addslashes($extusername).')');
        return count($users);
    }
484175
public function getName() {

		$name = $this->getFullName();

		if( empty( $name ) ) {

			$name	= $this->username;

			if( empty( $name ) ) {

				$name	= preg_split( '/@/', $this->email );
				$name	= $name[ 0 ];
			}
		}

		return $name;
	}
1249764
public function getCurrentUser()
    {
        if ($token = $this->tokenStorage->getToken()) {
            if (($user = $token->getUser()) && is_object($user)) {
                return $user;
            }
        }

        throw new \Exception('Authorization needed', ErrorCode::CODE_UNAUTHORIZED);
    }
862819
public function get($username) {


        if(is_numeric($username)) {
            $key = 'id';
        }
        else {
            $key = 'username';
        }

        $query = sprintf(self::SELECT_ALL,
            $this->params['table'],
            $this->params[$key],
            $this->pdo->quote($username));

        $stmt = $this->pdo->query($query);

		if(!$stmt) {
			$error = $this->pdo->errorInfo();
			
			throw new \Exception($error[2]);
		}
		
        if($user = $stmt->fetch(PDO::FETCH_ASSOC)) {
            return $user;
        }
        else {
            throw new UserException('User not found', 404);
        }
    }
157189
public function getName(){
		$result = null;
		if (isset($this->userInfo[$this->socialFieldsMap['name']])) {
			$result = $this->userInfo[$this->socialFieldsMap['name']];
			}
		return $result;
		}
994804
protected function getUserString() : string
    {
        $result = 'System';

        $userFields = [
            'name',
            'username',
            'email',
        ];

        $currentUser = User::getCurrentUser();
        if (empty($currentUser) || !is_array($currentUser)) {
            return $result;
        }

        foreach ($userFields as $field) {
            if (!empty($currentUser[$field])) {
                return $currentUser[$field];
            }
        }

        return $result;
    }