Log in as a specific WP user.

@since 17xxxx WP user utils.

@param int  $user_id  User ID.
@param bool $remember Remember them?

@return bool True if logged-in.
@note This updates cookies in real-time.
482286
public function loginAs(int $user_id, bool $remember = false): bool
    {
        if (!$user_id) {
            return false; // Impossible.
        }
        $on_set_auth_cookie = function (string $value) {
            $_COOKIE[is_ssl() ? SECURE_AUTH_COOKIE : AUTH_COOKIE] = $value;
        };
        $on_set_logged_in_cookie = function (string $value) {
            $_COOKIE[LOGGED_IN_COOKIE] = $value;
        };
        add_action('set_auth_cookie', $on_set_auth_cookie);
        add_action('set_logged_in_cookie', $on_set_logged_in_cookie);

        wp_clear_auth_cookie();
        wp_set_auth_cookie($user_id, $remember);

        remove_action('set_auth_cookie', $on_set_auth_cookie);
        remove_action('set_logged_in_cookie', $on_set_logged_in_cookie);

        wp_set_current_user(0);
        wp_set_current_user($user_id);

        return (int) get_current_user_id() === $user_id;
    }
425209
public static function authenticate(array $credentials, $remember = false, $login = true, $appId = null)
    {
        if (\Auth::attempt($credentials)) {
            $user = \Auth::getLastAttempted();
            /** @noinspection PhpUndefinedFieldInspection */
            static::checkRole($user->id);
            if ($login) {
                /** @noinspection PhpUndefinedFieldInspection */
                $user->last_login_date = Carbon::now()->toDateTimeString();
                /** @noinspection PhpUndefinedFieldInspection */
                $user->confirm_code = 'y';
                /** @noinspection PhpUndefinedMethodInspection */
                $user->save();
                /** @noinspection PhpParamsInspection */
                Session::setUserInfoWithJWT($user, $remember, $appId);
            }

            return true;
        } else {
            return false;
        }
    }
1336778
public function loginUsingId( $id, $remember = false )
	{
		$acct = $this->auth->retrieveById( $id );

		if ( !is_null( $acct ) )
		{
			$this->login( $acct, $remember );

			return $acct;
		}

		return false;
	}
672330
public function login($identity,$remember=false){
        $this->identity = $identity;
        $this->saveLoginSession();
        if($remember){
            return $this->saveLoginCookie();
        }
        return true;
    }
137909
public static function get_by_user_id($user_id) {
	$mysql = bootstrap::get_library('mysql');
	
	$sql   = "SELECT * FROM `login_github` WHERE `user_id` = %d;";
	$login = $mysql::select('row', $sql, $user_id);
	if (empty($login)) {
		return false;
	}
	
	return new static($login['id']);
}
1288753
public function login($user, $password)
    {
        $creds = array();
        $creds['user_login'] = $user;
        $creds['user_password'] = $password;
        $creds['remember'] = true;
        $user = wp_signon($creds, false);
        if (is_wp_error($user)) {
            return false;
        } else {
            return true;
        }
    }
227183
protected function setUserAccountOrder($user_id)
    {
        $this->data_user = $this->user->get($user_id);

        if (empty($this->data_user)) {
            $this->outputHttpStatus(404);
        }

        if (empty($this->data_user['status']) && !$this->access('user')) {
            $this->outputHttpStatus(403);
        }
    }
409173
public function force_login($user_id = '')
	{
		if (empty($user_id))
		{
			return false;
		}

		$this->user = \DB::select_array(\Config::get('simpleauth.table_columns', array('*')))
			->where_open()
			->where('id', '=', $user_id)
			->where_close()
			->from(\Config::get('simpleauth.table_name'))
			->execute(\Config::get('simpleauth.db_connection'))
			->current();

		if ($this->user == false)
		{
			$this->user = \Config::get('simpleauth.guest_login', true) ? static::$guest_login : false;
			\Session::delete('username');
			\Session::delete('login_hash');
			return false;
		}

		\Session::set('username', $this->user['username']);
		\Session::set('login_hash', $this->create_login_hash());
		return true;
	}
1218763
protected function _deleteObject( $user_id ) {
		$user = get_user_by( 'id', $user_id );
		if ( ! $user ) {
			return false;
		}

		$deleted = is_multisite()
			? wpmu_delete_user( $user_id )
			: wp_delete_user( $user_id );

		if ( $deleted ) {
			$this->_debug( 'Deleted user with ID: ' . $user_id );
			return true;
		}

		$this->_debug( 'User removal failed for ID: ' . $user_id );
		return false;
	}
718312
public function login(UserInterface $user, $remember = false)
    {
        $this->updateSession($user->getAuthIdentifier());

        // If the user should be permanently "remembered" by the application we will
        // queue a permanent cookie that contains the encrypted copy of the user
        // identifier. We will then decrypt this later to retrieve the users.
        if ($remember) {
            $this->createRememberTokenIfDoesntExist($user);

            $this->queueRecallerCookie($user);
        }

        // If we have an event dispatcher instance set we will fire an event so that
        // any listeners will hook into the authentication events and run actions
        // based on the login and logout events fired from the guard instances.
        if (isset($this->events)) {
            $this->events->dispatch('auth.login', array($user, $remember));
        }

        $this->setUser($user);
    }
1349275
public function login()
    {
        if ($this->validate() && $this->user) {
            $isLogged = Yii::$app->getUser()->login($this->user, $this->rememberMe ? $this->module->rememberFor : 0);

            if ($isLogged) {
                $this->user->updateAttributes(['last_login_at' => time()]);
            }

            return $isLogged;
        }

        return false;
    }
794589
public function saveSession($user_id = null, $provider = [])
    {
        if (empty($user_id)) {
            $user_id = activeUser('id');
        }

        if (empty($user_id)) {
            $this->setError('Must specify which user ID\'s session to save.');
            return false;
        }

        $oUser = $this->oUserModel->getById($user_id);

        if (!$oUser) {
            $this->setError('Invalid User ID');
            return false;
        }

        // --------------------------------------------------------------------------

        if (!is_array($provider)) {

            $_provider = (array) $provider;
            $_provider = array_unique($_provider);
            $_provider = array_filter($_provider);

        } else {

            $_provider = $provider;
        }

        // --------------------------------------------------------------------------

        $_session     = $this->oHybridAuth->getSessionData();
        $_session     = unserialize($_session);
        $_save        = [];
        $_identifiers = [];

        //  Now we sort the session into individual providers
        foreach ($_session as $key => $value) {

            //  Get the bits
            list($hauth, $provider) = explode('.', $key, 3);

            if (!isset($_save[$provider])) {
                $_save[$provider] = [];
            }

            $_save[$provider][$key] = $value;
        }

        // --------------------------------------------------------------------------

        //  Prune any which aren't worth saving
        foreach ($_save as $provider => $values) {

            //  Are we only interested in a particular provider?
            if (!empty($_provider)) {

                if (array_search($provider, $_provider) === false) {
                    unset($_save[$provider]);
                    continue;
                }
            }

            //  Connected?
            if (!$this->isConnectedWith($provider)) {
                unset($_save[$provider]);
                continue;
            }

            //  Got an identifier?
            try {

                $oAdapter = $this->oHybridAuth->getAdapter($provider);
                $oProfile = $oAdapter->getUserProfile();

                if (!empty($oProfile->identifier)) {
                    $_identifiers[$provider] = $oProfile->identifier;
                }

            } catch (\Exception $e) {
                unset($_save[$provider]);
                continue;
            }
        }

        // --------------------------------------------------------------------------

        /**
         * Get the user's existing data, so we know whether we're inserting or
         * updating their data
         */

        $this->oDb->where('user_id', $user_id);
        $aExisting = $this->oDb->get(NAILS_DB_PREFIX . 'user_social')->result();
        $aExists   = [];

        foreach ($aExisting as $existing) {
            $aExists[$existing->provider] = $existing->id;
        }

        // --------------------------------------------------------------------------

        //  Save data
        $this->oDb->trans_begin();

        $oNow = Factory::factory('DateTime');

        foreach ($_save as $provider => $keys) {

            if (isset($aExists[$provider])) {

                //  Update
                $aData = [
                    'identifier'   => $_identifiers[$provider],
                    'session_data' => serialize($keys),
                    'modified'     => $oNow->format('Y-m-d H:i{s'),
                ];

                $this->oDb->set($aData);
                $this->oDb->where('id', $aExists[$provider]);
                $this->oDb->update(NAILS_DB_PREFIX . 'user_social');

            } else {

                //  Insert
                $aData = [
                    'user_id'      => (int) $user_id,
                    'provider'     => $provider,
                    'identifier'   => $_identifiers[$provider],
                    'session_data' => serialize($keys),
                    'created'      => $oNow->format('Y-m-d H:i:s'),
                    'modified'     => $oNow->format('Y-m-d H:i:s'),
                ];

                $this->oDb->set($aData);
                $this->oDb->insert(NAILS_DB_PREFIX . 'user_social');
            }
        }

        // --------------------------------------------------------------------------

        if ($this->oDb->trans_status() === false) {
            $this->oDb->trans_rollback();
            return false;
        } else {
            $this->oDb->trans_commit();
            return true;
        }
    }
966605
public static function login( Account $acct, $remember = false )
	{
		static::__do( __FUNCTION__, args_with_keys( func_get_args(), __CLASS__, __FUNCTION__ ) );
	}
265199
public static function delete_by_user_id($user_id = null)
	{
		if (empty($user_id))
		{
			return true;
		}

		$results = self::all()
			->whereEquals('user_id', $user_id)
			->rows();

		foreach ($results as $result)
		{
			if (!$result->destroy())
			{
				return false;
			}
		}

		return true;
	}
771261
public function login(User $user, $password)
    {
        if ($user->isPasswordValid($password)) {
            $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
            $this->tokenStorage->setToken($token);
            $user->setLastLogin(new \DateTime());
            $this->save($user);

            return true;
        }

        return false;
    }
934005
public function login(string $userID): bool
    {
        $data = Internal\Server::call('login', ['userID' => $userID], true);
        if (isset($data['result'])) {
            return $data['result'] === 'ok';
        }
        return false;
    }
1310093
public function userGet(int $user_id)
    {
        $value = get_user_meta($user_id, $this->getName(), ! $this->getOption('multiple', false));

        if (! empty($value)) {
            $this->setValue($value);
        }
    }