Persists a login for the given user.

@param  User $user
@param  bool $remember

@return User|bool
764481
public function login(User $user, $remember = false)
    {
        return $this->sentinel->login($user, $remember);
    }
631227
public function setIdentity(Identity $user, $remember = false)
    {
        $this->identity = $user;

        Application::$instance->getResponse()->addCookie(self::TOKEN_NAME,
            $user->getAuthToken(),
            $remember ? time() + 365 * 24 * 60 * 60 : null, '/');
        return $this;
    }
1161609
public function login($credentials = array(), $remember = false, $secure = false)
	{
		$creds = array();

		$creds[$this->getLoginField()] = $this->getLoginCredential($credentials);

		$creds[$this->getPasswordField()] = $this->getPasswordCredential($credentials);

		$creds['remember'] = $remember;

		$user = wp_signon($creds, $secure);

		/**
		 * throw exception encapsulation of WP_Error
		 */
		if (is_wp_error($user))
		{
			throw new LoginFailedException($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->fire('auth.login', array($user, $remember));
		}

		$this->setUser($user);

		return true;
	}
501909
public function loginByRecord(User $user)
    {
        $this->loadRecordData($user);
        $this->session['user'] = $user->toArray($this->sessionFields);
        wei()->event->trigger('userLogin', [$user]);

        return ['code' => 1, 'message' => '登录成功'];
    }
1243141
public function updateRememberToken(UserContract $user, $token)
    {
        $this->query->filterById($user->getAuthIdentifier())
            ->update(['RememberToken' => $token]);
    }
1336336
public function enableRememberMe($user)
    {
        $rememberMeValue = $this->generateRememberMeCookie($user->getUsername());
        $this->session->set('REMEMBER_ME', $rememberMeValue);
    }
605184
protected function loginRememberedUser()
    {
        //  Is remember me functionality enabled?
        $oConfig = Factory::service('Config');
        $oConfig->load('auth/auth');

        if (!$oConfig->item('authEnableRememberMe')) {
            return false;
        }

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

        //  Get the credentials from the cookie set earlier
        $remember = get_cookie($this->sRememberCookie);

        if ($remember) {

            $remember = explode('|', $remember);
            $email    = isset($remember[0]) ? $remember[0] : null;
            $code     = isset($remember[1]) ? $remember[1] : null;

            if ($email && $code) {

                //  Look up the user so we can cross-check the codes
                $user = $this->getByEmail($email);

                if ($user && $code === $user->remember_code) {
                    //  User was validated, log them in!
                    $this->setLoginData($user->id);
                    $this->me = $user->id;
                }
            }
        }

        return true;
    }
1039492
public function exists(CanResetPassword $user, $token)
    {
        $email = $user->getEmailForPasswordReset();

        $reminder = $this->makeSelect()
                            ->where('o.email = :email')
                            ->andWhere('o.token = :token')
                            ->setParameter('email', $email)
                            ->setParameter('token', $token)
                            ->getQuery()
                            ->getOneOrNullResult();

        return $reminder != null && !$this->reminderExpired($reminder);
    }
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;
        }
    }
262849
public function authenticate($credentials, $remember = false, $login = true)
    {
        $response = $this->fireEvent('sentinel.authenticating', $credentials, true);

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

        if ($credentials instanceof UserInterface) {
            $user = $credentials;
        } else {
            $user = $this->users->findByCredentials($credentials);

            $valid = $user !== null ? $this->users->validateCredentials($user, $credentials) : false;

            if ($user === null || $valid === false) {
                $this->cycleCheckpoints('fail', $user, false);

                return false;
            }
        }

        if (! $this->cycleCheckpoints('login', $user)) {
            return false;
        }

        if ($login === true) {
            $method = $remember === true ? 'loginAndRemember' : 'login';

            if (! $user = $this->{$method}($user)) {
                return false;
            }
        }

        $this->fireEvent('sentinel.authenticated', $user);

        return $this->user = $user;
    }
1249440
public function resetPassword(User $user)
    {
        $newPassword = uniqid(time(), true);
        $user->setPassword($newPassword);
        $this->save($user);

        return $newPassword;
    }
995844
public function save(User $user)
    {
        if ($user->getId() != null) {
            return $this->update($user);
        }
        return $this->create($user);
    }
1273014
public function resetPasswordAction(Request $request, User $user)
    {
        $form = $this->createFormBuilder(null, $this->getDefaultFormOptions($request, $user->getId()))->getForm();

        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            $this->get(UserManagerInterface::class)->requestNewPassword($user);
            $this->saveEntity($user);

            if ($request->isXmlHttpRequest()) {
                return array_merge(
                    $this->getViewParameters($request, $form, $user),
                    [
                        'dataId' => $user->getId(),
                        'success' => 1,
                    ]
                );
            }

            return $this->redirectToAction('list');
        }

        return $this->renderAction(
            array_merge(
                $this->getViewParameters($request, $form, $user),
                [
                    'dataId' => $user->getId(),
                ]
            )
        );
    }
491958
public function login(array $credentials, $remember = true)
    {
        $uniqueAlias = strpos($credentials['username'], '@') ? 'email' : 'username';
        $person = $this->getService('repos:people.person')->find(array(
            $uniqueAlias => $credentials['username'],
            'enabled' => 1
        ));

        if (is_null($person)) {
            $msg = "Did not find a user with username: ".$credentials['username'];
            throw new AnErrorException($msg, AnHttpResponse::UNAUTHORIZED);
        } else {
            $person->visited();
            $this->_createSession($person);

            $results = dispatch_plugin('user.onAfterLoginPerson', array('person' => $person));
            foreach ($results as $result) {
                if ($result instanceof Exception || $result === false) {
                    return false;
                }
            }
        }

        // create a remember cookie that contains the ecrypted username and password
        if ($remember) {
            $key = get_hash('AN_LOGIN_REMEMBER', 'md5');
            $crypt = $this->getService('anahita:encrypter', array('key' => $key, 'cipher' => 'AES-256-CBC'));
            $cookie = $crypt->encrypt(serialize(array(
                'username' => $credentials['username'],
                'password' => $credentials['password'],
            )));
            $oneYear = 365 * 24 * 3600;
            $hash = get_hash('AN_LOGIN_REMEMBER');
            setcookie($hash, $cookie, time() + $oneYear, '/');
        }

        return $person;
    }
68247
public function authenticate($credentials, $remember = false, $login = true)
    {
        try {
            $user = $this->sentinel->authenticate($credentials, $remember, $login);
        } catch (Exception $e) {
            return $this->returnException($e);
        }

        if ($user) {
            $message = request()->expectsJson() ?
                $this->translate('session_initated', 'You have been authenticated.') : null;
            return new SuccessReply($message);
        }

        $message = $this->translate('failed_authorization', 'Access denied due to invalid credentials.');
        return new FailureReply($message);
    }
212253
protected function fireLoginEvent($user, $remember = false)
    {
        if (isset($this->events)) {
            $this->events->dispatch(new Events\Login(
                $this->name, $user, $remember
            ));
        }
    }
66836
private function encodePassword(User $user)
    {
        $password = $this->encoderFactory
            ->getEncoder($user)
            ->encodePassword($user->getPlainPassword(), $user->getSalt());

        $user->setPassword($password);

        return $password;
    }