Try logging in as a user with the given email and password.

@param $redirect the registered redirect URI
@return a valid {@link User}
@throws UserAuthenticationException if the user could not be logged in, with a reason
494146
static function tryLogin(\Db\Connection $db, OAuth2Providers $provider) {
    $user = UserOAuth2::auth($provider->getProvider());
    if (!$user) {
      throw new UserAuthenticationException("Could not login user with OAuth2.");
    }

    $uid = $user->uid;
    if (!$uid) {
      throw new UserAuthenticationException("No UID found.");
    }

    // find the user with the uid
    $q = $db->prepare("SELECT users.* FROM users
        JOIN user_oauth2_identities ON users.id=user_oauth2_identities.user_id
        WHERE uid=? AND provider=? LIMIT 1");
    $q->execute(array($uid, $provider->getKey()));

    if ($user_instance = $q->fetch()) {
      $result = new User($user_instance);
      $result->setIdentity($provider->getKey() . ":" . $uid);
      return $result;
    } else {
      // issue #266: If we are using Google, we might have an OpenID account that hasn't been connected yet,
      // in which case we can find it here and connect it
      if (isset($provider->getProvider()->id_token) && isset($provider->getProvider()->id_token['openid_id'])) {
        $id_token = $provider->getProvider()->id_token;

        $q = $db->prepare("SELECT * FROM user_openid_identities WHERE identity=?");
        $q->execute(array($id_token['openid_id']));

        if ($openid_identity = $q->fetch()) {
          // create a new identity
          $q = $db->prepare("INSERT INTO user_oauth2_identities SET user_id=?, provider=?, uid=?");
          $q->execute(array($openid_identity['user_id'], $provider->getKey(), $uid));

          return User::findUser($db, $openid_identity['user_id']);
        }
      }

      throw new UserAuthenticationMissingAccountException("No such '" . $provider->getKey() . "' user found.");
    }
  }
1021722
public function actionLogout($redirect = null)
	{
		\App::$domain->account->auth->logout();
		\App::$domain->navigation->alert->create(['account/auth', 'logout_success'], Alert::TYPE_SUCCESS);
		if($redirect) {
            return $this->redirect([SL . $redirect]);
        } else {
            return $this->goHome();
        }
	}
389856
public function redirect()
    {
        $state = null;

        if ($this->usesState()) {
            $this->request->session()->put('state', $state = $this->getState());
        }

        return new RedirectResponse($this->getAuthUrl($state));
    }
832246
public function createPersonalAccessClient($userId, $name, $redirect)
    {
        return tap($this->create($userId, $name, $redirect, true), function ($client) {
            $accessClient = Passport::personalAccessClient();
            $accessClient->client_id = $client->id;
            $accessClient->save();
        });
    }
841397
public function getUser($authenticate = true)
    {
        if ($this->user) {
            return $this->user;
        } elseif (! $authenticate) {
            return;
        }

        try {
            return $this->user = $this->authenticate();
        } catch (Exception $exception) {
            return;
        }
    }
364959
public function setRedirect($redirect) {
        if (!is_bool($redirect)) throw new IllegalTypeException('Illegal type of parameter $redirect: '.gettype($redirect));

        $this->redirect = $redirect;
        return $this;
    }
1138168
public function login(AuthenticationRequest $request)
    {
        // Prepare variables
        $loginField = get_login_field($request->input($this->username()));
        $credentials = [
            'is_active' => true,
            $loginField => $request->input('loginfield'),
            'password' => $request->input('password'),
        ];

        // If the class is using the ThrottlesLogins trait, we can automatically throttle
        // the login attempts for this application. We'll key this by the username and
        // the IP address of the client making these requests into this application.
        if ($this->hasTooManyLoginAttempts($request)) {
            $this->fireLockoutEvent($request);

            return $this->sendLockoutResponse($request);
        }

        if (auth()->guard($this->getGuard())->attempt($credentials, $request->filled('remember'))) {
            return $this->sendLoginResponse($request);
        }

        // If the login attempt was unsuccessful we will increment the number of attempts
        // to login and redirect the user back to the login form. Of course, when this
        // user surpasses their maximum number of attempts they will get locked out.
        $this->incrementLoginAttempts($request);

        return $this->sendFailedLoginResponse($request);
    }
690488
public function authenticationUrl($redirect, $approvalPrompt = 'auto', $scope = null, $state = null)
        {
            $parameters = array(
                'client_id'       => $this->clientId,
                'redirect_uri'    => $redirect,
                'response_type'   => 'code',
                'approval_prompt' => $approvalPrompt,
                'state'           => $state,
            );

            if (! is_null($scope)) {
                $parameters['scope'] = $scope;
            }

            return $this->parseGet(
                $this->authUrl . 'authorize',
                $parameters
            );
        }
775723
private function runCommand(string $command, string $redirect = '2>&1')
    {
        $pd = popen($command . ' ' . $redirect, 'r');
        if (false === $pd) {
            throw new \RuntimeException('Can not execute ' . $command);
        }

        return $pd;
    }
1130206
public function login(Request $request)
    {
        $this->validate($request, [
            'email'    => 'required',
            'password' => 'required',
        ]);

        if (
            $this->core->auth()
                ->login($request->input('email'), $request->input('password'), $request->has('remember'))
        ) {
            return redirect()->intended(
                $this->core->route(NamedRoute::HOME)
            );
        }

        return redirect()->back()
            ->withInput($request->only('email', 'remember'))
            ->withErrors([
                'email' => Lang::has('cms::auth.failed')
                    ?   Lang::get('cms::auth.failed')
                    :   'These credentials do not match our records.',
            ]);
    }
545164
public function isAdmin($redirect = false)
    {

        if (!$this->isLoggedIn()) {
            $this->di->get("response")->redirect("user/login");
            return false;
        }

        $email = $this->di->get("session")->get("user");
        $user = new User();
        $user->setDb($this->di->get("db"));
        $user->find("email", $email);
        $isAdmin = $user->admin;

        if (!$isAdmin) {
            if ($redirect) {
                $this->di->get("response")->redirect("user");
            }
            return false;
        }

        return true;
    }
307724
public function login(LoginRequest $request, JWTAuth $JWTAuth)
    {
        $credentials = $request->only(['email', 'password']);

        try {
            $token = \JWTAuth::attempt($credentials);

            event(new Login(\JWTAuth::user(), false));

            if (!$token) {
                throw new AccessDeniedHttpException(__('auth.failed'));
            }

        } catch (JWTException $e) {
            throw new HttpException(500);
        }

        return response()
            ->json([
                'status'     => 'ok',
                'token'      => $token,
                'expires_in' => Auth::guard()->factory()->getTTL() * 60
            ]);
    }
332388
private function getRedirect($currentRoute, $redirect = false)
    {
        $useRedirect = $this->options->getUseRedirectParameterIfPresent();
        $routeExists = ($redirect && $this->routeExists($redirect));
        if (!$useRedirect || !$routeExists) {
            $redirect = false;
        }

        switch ($currentRoute) {
            case 'zfcuser/login':
            case 'scn-social-auth-user/login':
            case 'scn-social-auth-user/register':
            case 'scn-social-auth-user/authenticate/provider':
            case 'scn-social-auth-user/add-provider/provider':
                $route = ($redirect) ?: $this->options->getLoginRedirectRoute();

                return $this->router->assemble(array(), array('name' => $route));
                break;
            case 'zfcuser/logout':
            case 'scn-social-auth-user/logout':
                $route = ($redirect) ?: $this->options->getLogoutRedirectRoute();

                return $this->router->assemble(array(), array('name' => $route));
                break;
            default:
                return $this->router->assemble(array(), array('name' => 'zfcuser'));
        }
    }
1015129
public static function login($userLogin, $userPassword)
    {
        try {
            $user = self::authenticate($userLogin, $userPassword);
            $loggedIn = self::startSession($user);
        } catch (common_user_auth_AuthFailedException $e) {
            $loggedIn = false;
        }
        return $loggedIn;
    }
305292
public function auth(LoginForm $form): User
    {
        $this->checkFailure();
        $user = $this->user->findByUsernameOrEmail($form->username);
        if (!$user || !$user->validatePassword($form->password)) {
            $this->setFailure();
            throw new \DomainException($this->i18n->t('setrun/user', 'Wrong Username or Password'));
        }
        if ($user && $user->status == User::STATUS_BLOCKED) {
            throw new \DomainException($this->i18n->t('setrun/user', 'Account temporarily blocked'));
        }
        if ($user && $user->status == User::STATUS_WAIT) {
            throw new \DomainException($this->i18n->t('setrun/user', 'Account not confirmed'));
        }
        $this->removeFailure();
        return $user;
    }
1047657
public function redirect()
    {
        $this->request->getSession()->set(
            'oauth.temp', $temp = $this->server->getTemporaryCredentials()
        );

        return new RedirectResponse($this->server->getAuthorizationUrl($temp));
    }
325880
public function handleLogin(Login $request)
    {
        // Set the auth data
        $userData = [
            'username' => $request->get('username'),
            'password' => $request->get('password'),
        ];

        // Log in successful
        if (auth()->attempt($userData, $request->get('remember', false))) {
            event(new UserLoggedIn(auth()->user()));

            return redirect()
                ->intended(route('home'))
                ->with('message', 'You have been logged in.');
        }

        // Login failed
        return redirect(route('auth.login'))
            ->with('errors', ['Your username or password was incorrect.']);
    }