Determine the format to use for a bind username going to LDAP.

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

        return preg_replace($this->params, $replacements, $this->bindFormat);
    }
423797
public function getUser($username)
    {
        $resellers = $this->getUsers();
        return isset($resellers[$username]) ? $resellers[$username] : null;
    }
1162425
protected function getUserByName(string $username)
    {
        $found_user = null;
        $users      = $this->getWordpressParameter('users');

        foreach ($users as $user) {
            if ($username === $user['username']) {
                $found_user = $user;
                break;
            }
        }

        if ($found_user === null) {
            throw new RuntimeException("[W801] User not found for name \"{$username}\"");
        }

        return $found_user;
    }
616740
public function userUsernameFromLdapEntry($ldap_entry) {


    if ($this->account_name_attr) {
      $accountname = (empty($ldap_entry[$this->account_name_attr][0])) ? FALSE : $ldap_entry[$this->account_name_attr][0];
    }
    elseif ($this->user_attr)  {
      $accountname = (empty($ldap_entry[$this->user_attr][0])) ? FALSE : $ldap_entry[$this->user_attr][0];
    }
    else {
      $accountname = FALSE;
    }

    return $accountname;
  }
150182
function authenticate($username,$password,$prevent_rebind=false){
        if ($username==NULL || $password==NULL){ return (false); } //prevent null binding
        
        //bind as the user		
        $this->_bind = @ldap_bind($this->_conn,$username.$this->_account_suffix,$password);
        $this->_bind_paged = @ldap_bind($this->_conn_paged,$username.$this->_account_suffix,$password);
        if (!$this->_bind){ return (false); }
        
        //once we've checked their details, kick back into admin mode if we have it
        if ($this->_ad_username!=NULL && !$prevent_rebind){
            $this->_bind = @ldap_bind($this->_conn,$this->_ad_username.$this->_account_suffix,$this->_ad_password);
            $this->_bind_paged = @ldap_bind($this->_conn_paged,$this->_ad_username.$this->_account_suffix,$this->_ad_password);
            if (!$this->_bind){
                // Modified by SysCo/al
                $this->_error = TRUE;
                $this->_error_message = 'FATAL: AD rebind failed.';
                exit();
            } //this should never happen in theory
        }
        
        return (true);
    }
1170107
private function resolveUser($username)
    {
        if (isset($this->knownUsers[strtolower($username)])) {
            return $this->knownUsers[strtolower($username)];
        }

        $repository = $this->entityManager->getRepository(User::class);
        $user = $repository->findOneBy(['uName' => $username]);

        // If we couldn't find the user by username, let's try to get it by email
        if (!$user) {
            $user = $repository->findOneBy(['uEmail' => $username]);
        }

        // No user to actually track against.
        if (!$user) {
            return null;
        }

        /**
         * I don't know what detach is doing or why it's here, but it's causing an exception on UserSignup
         * not being a known entity. Much like drugs, `detach` is not the answer
         */
        //$this->entityManager->detach($user);
        $this->knownUsers[strtolower($username)] = $user;
        return $user;
    }
54815
function user_activate($username) {
        $extusername = core_text::convert($username, 'utf-8', $this->config->ldapencoding);

        $ldapconnection = $this->ldap_connect();

        $userdn = $this->ldap_find_userdn($ldapconnection, $extusername);
        switch ($this->config->user_type)  {
            case 'edir':
                $newinfo['loginDisabled'] = 'FALSE';
                break;
            case 'rfc2307':
            case 'rfc2307bis':
                // Remember that we add a '*' character in front of the
                // external password string to 'disable' the account. We just
                // need to remove it.
                $sr = ldap_read($ldapconnection, $userdn, '(objectClass=*)',
                                array('userPassword'));
                $info = ldap_get_entries($ldapconnection, $sr);
                $info[0] = array_change_key_case($info[0], CASE_LOWER);
                $newinfo['userPassword'] = ltrim($info[0]['userpassword'][0], '*');
                break;
            case 'ad':
                // We need to unset the ACCOUNTDISABLE bit in the
                // userAccountControl attribute ( see
                // http://support.microsoft.com/kb/305144 )
                $sr = ldap_read($ldapconnection, $userdn, '(objectClass=*)',
                                array('userAccountControl'));
                $info = ldap_get_entries($ldapconnection, $sr);
                $info[0] = array_change_key_case($info[0], CASE_LOWER);
                $newinfo['userAccountControl'] = $info[0]['useraccountcontrol'][0]
                                                 & (~AUTH_AD_ACCOUNTDISABLE);
                break;
            default:
                print_error('user_activatenotsupportusertype', 'auth_ldap', '', $this->config->user_type_name);
        }
        $result = ldap_modify($ldapconnection, $userdn, $newinfo);
        $this->ldap_close();
        return $result;
    }
376838
public static function userName($name = null)
    {
        if ($name === null) {
            if (rand(1, 10) > 5) {
                $name = Name::firstName() . ' ' . Name::lastName();
            } else {
                $name = Name::firstName();
            }
        }

        $glue = array('.', '_');
        shuffle($glue);
        $nameParts = explode(' ', $name);
        shuffle($nameParts);
        $userName = implode($glue[0], $nameParts);

        return strtolower($userName);
    }
1016791
public static function deleteUser($username)
	{
		if ( ! self::userExists( $username ) ) return false;

		$deleted_user = self::$auth['users'][ $username ];
		unset( self::$auth['users'][ $username ] );

		return $deleted_user;
	}
160265
public function loadUserByUsername($username)
    {
        $slackUser = $this->client->getSlackUserFromOAuthCode($username);

        if (!$slackUser->isValid()) {
            throw new UsernameNotFoundException('No access token found.');
        }

        $user = $this->userService->findBySlackUserId($slackUser->getUserId());

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

        $user = $this->userService->findUserByEmail($slackUser->getEmail());

        if (!empty($user)) {
            $user->setSlackUserId($slackUser->getUserId());

            return $user;
        }

        return $this->registerUser($slackUser);
    }
1259733
public function deleteUser($username)
    {
        $stmt = $this
            ->conn
            ->prepare(sprintf("DELETE * FROM %s WHERE user_name = :name", $this->table))
            ->execute(['name' => $username]);
        return $stmt->rowCount();
    }
1257136
public function ldap_bind($ldap, $dn = NULL, $password = NULL)
	{
		return \ldap_bind($ldap, $dn, $password);
	}
378931
private function getUserUrl($username)
    {
        $base  = parse_url($this->url, PHP_URL_HOST);
        $proto = parse_url($this->url, PHP_URL_SCHEME);

        return sprintf('%s://%s/%s', $proto, $base, $username);
    }
1194055
public function bind($username = null, $password = null, $nosub = 0)
	{
		if (!$this->isConnected())
		{
			if (!$this->connect())
			{
				return false;
			}
		}

		if ($username === null)
		{
			$username = $this->username;
		}

		if ($password === null)
		{
			$password = $this->password;
		}

		$this->setDn($username, $nosub);

		$this->isBound = ldap_bind($this->resource, $this->getDn(), $password);

		return $this->isBound;
	}
1247800
public function getToken($username)
	{
		return isset($this->access_tokens[$username]) ? $this->access_tokens[$username] : null;
	}
227128
function password_expire($username) {
        $result = 0;

        $extusername = core_text::convert($username, 'utf-8', $this->config->ldapencoding);

        $ldapconnection = $this->ldap_connect();
        $user_dn = $this->ldap_find_userdn($ldapconnection, $extusername);
        $search_attribs = array($this->config->expireattr);
        $sr = ldap_read($ldapconnection, $user_dn, '(objectClass=*)', $search_attribs);
        if ($sr)  {
            $info = ldap_get_entries_moodle($ldapconnection, $sr);
            if (!empty ($info)) {
                $info = $info[0];
                if (isset($info[$this->config->expireattr][0])) {
                    $expiretime = $this->ldap_expirationtime2unix($info[$this->config->expireattr][0], $ldapconnection, $user_dn);
                    if ($expiretime != 0) {
                        $now = time();
                        if ($expiretime > $now) {
                            $result = ceil(($expiretime - $now) / DAYSECS);
                        } else {
                            $result = floor(($expiretime - $now) / DAYSECS);
                        }
                    }
                }
            }
        } else {
            error_log($this->errorlogtag.get_string('didtfindexpiretime', 'auth_ldap'));
        }

        return $result;
    }
1040837
public static function signInAs($username)
	{
		$ip = self::getClientIp();
		$ua = ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? $_SERVER['HTTP_USER_AGENT'] : '';
		$ts = date("U");
		$cu = self::getCurrentUsername();

		self::sessionWrite( array( 'username' => $username ) );
		self::reload();

		self::log( 'signinas ' . $username , $cu, $ts , $ip , $ua );
		self::save();

		return self::$auth['users'][ $username ];
	}