LDAP Auth.

@param string $username
@param string $password

@return bool
969046
public function plainAuth(string $username, string $password): bool
    {
        $resource = $this->ldap->getResource();

        $esc_username = ldap_escape($username);
        $filter = htmlspecialchars_decode(sprintf($this->account_filter, $esc_username));
        $result = ldap_search($resource, $this->ldap->getBase(), $filter, ['dn', $this->identity_attribute]);
        $entries = ldap_get_entries($resource, $result);

        if (0 === $entries['count']) {
            $this->logger->warning("user not found with ldap filter [{$filter}]", [
                'category' => get_class($this),
            ]);

            return false;
        }
        if ($entries['count'] > 1) {
            $this->logger->warning("more than one user found with ldap filter [{$filter}]", [
                'category' => get_class($this),
            ]);

            return false;
        }

        $dn = $entries[0]['dn'];
        $this->logger->info("found ldap user [{$dn}] with filter [{$filter}]", [
            'category' => get_class($this),
        ]);

        $result = ldap_bind($resource, $dn, $password);
        $this->logger->info("bind ldap user [{$dn}]", [
            'category' => get_class($this),
            'result' => $result,
        ]);

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

        if (!isset($entries[0][$this->identity_attribute])) {
            throw new Exception\IdentityAttributeNotFound('identity attribute not found');
        }

        $this->identifier = $entries[0][$this->identity_attribute][0];
        $this->ldap_dn = $dn;

        return true;
    }
198764
public function authenticate($username, $password)
    {
        $result = $this->getGateway()->authenticate($username, $password);
        $messages = $result->getMessages();

        // all messages beyond the first one are for debugging and
        // not suitable to display to the user.
        foreach ($messages as $i => $message) {
            if ($i > 0) {
                $this->getLogger()->debug(str_replace("\n", "\n  ", $message));
            }
        }

        $message = $messages[0]; // first message is user readable, suitable for showing on login form

        // show better errors than the defaults for various status codes returned by LDAP
        if (!empty($messages[1]) && strpos($messages[1], 'NT_STATUS_ACCOUNT_LOCKED_OUT') !== false) {
            $message = _t(
                __CLASS__ . '.ACCOUNTLOCKEDOUT',
                'Your account has been temporarily locked because of too many failed login attempts. ' .
                'Please try again later.'
            );
        }
        if (!empty($messages[1]) && strpos($messages[1], 'NT_STATUS_LOGON_FAILURE') !== false) {
            $message = _t(
                __CLASS__ . '.INVALIDCREDENTIALS',
                'The provided details don\'t seem to be correct. Please try again.'
            );
        }

        return [
            'success' => $result->getCode() === 1,
            'identity' => $result->getIdentity(),
            'message' => $message,
            'code' => $result->getCode()
        ];
    }
294278
public function authenticate($username, $password)
	{
		$this->debug->groupCollapsed(__METHOD__);
		$return = false;
		$users = $this->search(array(
			'username'	=> $username,
			'email'		=> $username,
		));
		if ($users && $this->verifyPassword($password, $users[0]['password'])) {
			$this->debug->info('login success');
			$this->log('login', $users[0]['userid']);
			$return = $users[0]['userid'];
		} else {
			$this->debug->warn('login failed');
			$userid = $users
				? $users[0]['userid']
				: null;
			$this->log('loginFail', $userid);
		}
		$this->debug->groupEnd();
		return $return;
	}
1119318
public function login($username, $password)
    {
        $model       = $this->slice->getRequired('model');
        $loginFields = $this->slice->getRequired('loginFields');
        $hashField   = $this->slice->getRequired('hashField');

        $userQuery = $this->provider->auth()->orm()->repository($model);

        foreach ($loginFields as $field)
        {
            $userQuery->whereOr($field, $username);
        }

        $user = $userQuery->findOne();

        if ($user && $this->verify($password, $user->get($hashField)))
        {
            $this->provider->setUser($user);
        }

        return $user;
    }
744973
public function checkUserCredentials($username, $password)
	{
		// allow authentication via email, just like in the hub
		if (strpos($username, '@'))
		{
			$username = $this->getUsernameFromEmail($username);
		}

		// use hubzero password library to compare stored password with sent password
		$match = Password::passwordMatches($username, $password, true);

		// return if match was found
		return (bool) $match;
	}
532767
public static function signIn($username , $password)
	{
		$ip = self::getClientIp();
		$ua = ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? $_SERVER['HTTP_USER_AGENT'] : '';
		$ts = date("U");

		if ( self::isValidPassword($username , $password) ) {

			self::sessionWrite( array( 'username' => $username ) );
			self::reload();
			self::$auth['users'][ $username ]['logincount'] = (int) @self::$auth['users'][ $username ]['logincount'] + 1;
			self::$auth['users'][ $username ]['lastlogin'] = array(
				'ip' => $ip,
				'ua' => $ua,
				'ts' => $ts
			);
			self::log( 'signin' , $username , $ts , $ip , $ua );
			self::save();

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

		self::log( 'signinerr' , $username , $ts , $ip , $ua );
		self::save();

		return false;
	}
507443
public function basic(string $username, string $password)
    {
        $this->type = self::BASIC;
        $this->username = $username;
        $this->password = $password;
    }
1167448
public function authenticate($userName, $password)
    {
        $this->beforeLogin($userName, $password);
        $result = $this->adapter->authenticate($userName, $password);
        if ($result) {
            $this->profile->loadProfile("$this->userNameFieldName = '$userName'");
            $this->profile->resetToken();
        }
        $this->afterLogin($userName, $password, $result);
        return $result;
    }
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);
    }
133692
public function setCredentials($username, $password)
    {
        $this->username = $username;
        $this->password = $password;

        return $this;
    }
1188805
private function createUserFromLDAP($userName)
    {
        $user = null;

        $ldapUser = $this->getLDAPUser($userName);
        // If we found the user in LDAP
        if (true == $ldapUser ) {
            $firstName = $ldapUser->getFirstAttribute(Settings::get('eloquent-ldap.first_name_field'));
            $lastName  = $ldapUser->getFirstAttribute(Settings::get('eloquent-ldap.last_name_field'));
            $email     = $ldapUser->getFirstAttribute(Settings::get('eloquent-ldap.email_field'));
            $enabled   = (($ldapUser->getFirstAttribute('useraccountcontrol') & 2) == 0);

            $userModel = $this->createUserModel();

            $ldapFields = [ 'username'      => $userName,
                            'first_name'    => $firstName,
                            'last_name'     => $lastName,
                            'email'         => $email,
                            'enabled'       => $enabled,
                          ];

            $validator = Validator::make($ldapFields, $userModel::getCreateValidationRules($this->app));

            if ($validator->fails()) {
                Log::error('Validation failed for user ['.$userName.'], in [EloquentLDAPUserProvider::createUserFromLDAP].');
                $messages = $validator->errors();
                foreach ($messages->all() as $message) {
                    Log::error('Validation message: ' . $message);
                }

            }
            else {
                $user = $userModel->create(array(
                    'username'   => $userName,
                    'first_name' => $firstName,
                    'last_name'  => $lastName,
                    'email'      => $email,
                    'password'   => 'Password handled by AD/LDAP.',
                    'auth_type'  => Settings::get('eloquent-ldap.label_ldap'),
                ));

                if ($enabled) {
                    $user->enabled = true;
                } else {
                    $user->enabled = false;
                }
                $user->save();

                if (Settings::get('eloquent-ldap.replicate_group_membership')) {
                    $this->replicateMembershipFromLDAP($user);
                }
            }

        }

        return $user;
    }
1286691
public function stateless($username, $password)
    {
        $user = $this->sentinel->stateless(
            [
                'email'    => $username,
                'password' => $password,
            ]
        );

        if ( ! ($user instanceof CartalystUserInterface)) {
            return false;
        }

        // This is still a login, and while we don't want persistence, we do want it to be recorded
        $this->sentinel->getUserRepository()->recordLogin($user);

        event( new CmsUserLoggedIn($user, true) );
        return true;
    }
1307965
public function bind($username, $password, $sasl = false)
    {
        if ($sasl) {
            if ($this->suppressErrors) {
                return $this->bound = @ldap_sasl_bind($this->getConnection(), null, null, 'GSSAPI');
            }

            return $this->bound = ldap_sasl_bind($this->getConnection(), null, null, 'GSSAPI');
        } else {
            if ($this->suppressErrors) {
                return $this->bound = @ldap_bind($this->getConnection(), $username, $password);
            }

            return $this->bound = ldap_bind($this->getConnection(), $username, $password);
        }
    }
492290
public function checkUserCredentials($username, $password)
    {
        $user = $this->getUserDetails($username);

        return $user && $user['password'] === $password;
    }
983226
public function userWithPass($username, $password)
    {
        $header = base64_encode(sprintf('%s:%s', $username, $password));

        $this->headers['Authorization'] = 'Basic ' . $header;
    }
490428
public function connect($username, $password)
    {
        $error = parent::connect($username, $password);

        if ($error) {
            return $error;
        }

        return $this->load_script();
    }
933669
public function setHttpAuth(string $username, string $password = ''): AbstractApi
    {
        $this->httpAuth['username'] = $username;
        $this->httpAuth['password'] = $password;

        return $this;
    }