Action: Login
Synopsis: Login Manager
Privilege: <none>

@return void
432434
protected function login()
    {
        $this->state = self::CONN_STATE_LOGIN_PACKET_SENT;
        $this->write(
            "Action: login\r\n"
            . "Username: " . $this->username . "\r\n"
            . "Secret: " . $this->secret . "\r\n"
            . "Events: on\r\n"
            . "\r\n"
        );
    }
54642
public function index(): void
    {
        if (!userHasPermission('admin:auth:settings:update:.*')) {

            unauthorised();
        }

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

        $oSocial                 = Factory::service('SocialSignOn', 'nails/module-auth');
        $providers               = $oSocial->getProviders();
        $this->data['providers'] = $providers;

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

        if ($this->input->post()) {

            //  Prepare update
            $settings          = [];
            $settingsEncrypted = [];

            if (userHasPermission('admin:auth:settings:update:registration')) {

                $settings['user_registration_enabled'] = $this->input->post('user_registration_enabled');
            }

            if (userHasPermission('admin:auth:settings:update:password')) {

                //  @todo
            }

            if (userHasPermission('admin:auth:settings:update:social')) {

                /**
                 * Disable social signon, if any providers are proeprly enabled it'll
                 * turn itself on again.
                 */

                $settings['auth_social_signon_enabled'] = false;

                foreach ($providers as $provider) {

                    $settings['auth_social_signon_' . $provider['slug'] . '_enabled'] = (bool) $this->input->post('auth_social_signon_' . $provider['slug'] . '_enabled');

                    if ($settings['auth_social_signon_' . $provider['slug'] . '_enabled']) {

                        //  null out each key
                        if ($provider['fields']) {

                            foreach ($provider['fields'] as $key => $label) {

                                if (is_array($label) && !isset($label['label'])) {

                                    foreach ($label as $key1 => $label1) {

                                        $value = $this->input->post('auth_social_signon_' . $provider['slug'] . '_' . $key . '_' . $key1);

                                        if (!empty($label1['required']) && empty($value)) {
                                            $error = 'Provider "' . $provider['label'] . '" was enabled, but was missing required field "' . $label1['label'] . '".';
                                            break 3;
                                        }

                                        if (empty($label1['encrypted'])) {
                                            $settings['auth_social_signon_' . $provider['slug'] . '_' . $key . '_' . $key1] = $value;
                                        } else {
                                            $settingsEncrypted['auth_social_signon_' . $provider['slug'] . '_' . $key . '_' . $key1] = $value;
                                        }
                                    }

                                } else {

                                    $value = $this->input->post('auth_social_signon_' . $provider['slug'] . '_' . $key);

                                    if (!empty($label['required']) && empty($value)) {
                                        $error = 'Provider "' . $provider['label'] . '" was enabled, but was missing required field "' . $label['label'] . '".';
                                        break 2;
                                    }

                                    if (empty($label['encrypted'])) {
                                        $settings['auth_social_signon_' . $provider['slug'] . '_' . $key] = $value;
                                    } else {
                                        $settingsEncrypted['auth_social_signon_' . $provider['slug'] . '_' . $key] = $value;
                                    }
                                }
                            }
                        }

                        //  Turn on social signon
                        $settings['auth_social_signon_enabled'] = true;

                    } else {

                        //  null out each key
                        if ($provider['fields']) {

                            foreach ($provider['fields'] as $key => $label) {

                                /**
                                 * Secondary conditional detects an actual array fo fields rather than
                                 * just the label/required array. Design could probably be improved...
                                 **/

                                if (is_array($label) && !isset($label['label'])) {

                                    foreach ($label as $key1 => $label1) {
                                        $settings['auth_social_signon_' . $provider['slug'] . '_' . $key . '_' . $key1] = null;
                                    }

                                } else {
                                    $settings['auth_social_signon_' . $provider['slug'] . '_' . $key] = null;
                                }
                            }
                        }
                    }
                }
            }

            //  Save
            if (!empty($settings)) {

                if (empty($error)) {

                    $oDb = Factory::service('Database');
                    $oDb->trans_begin();

                    $bRollback          = false;
                    $oAppSettingService = Factory::service('AppSetting');

                    if (!empty($settings)) {
                        if (!$oAppSettingService->set($settings, 'auth')) {
                            $error     = $oAppSettingService->lastError();
                            $bRollback = true;
                        }
                    }

                    if (!empty($settingsEncrypted)) {
                        if (!$oAppSettingService->set($settingsEncrypted, 'auth', null, true)) {
                            $error     = $oAppSettingService->lastError();
                            $bRollback = true;
                        }
                    }

                    if ($bRollback) {

                        $oDb->trans_rollback();
                        $this->data['error'] = 'There was a problem saving authentication settings.';

                    } else {

                        $oDb->trans_commit();
                        $this->data['success'] = 'Authentication settings were saved.';

                    }

                } else {
                    $this->data['error'] = 'There was a problem saving authentication settings. ' . $error;
                }

            } else {
                $this->data['message'] = 'No settings to save.';
            }
        }

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

        //  Existing settings
        $this->data['settings'] = appSetting(null, 'auth', true);

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

        //  Load assets
        $oAsset = Factory::service('Asset');
        $oAsset->load('nails.admin.settings.min.js', 'NAILS');

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

        //  Set page title
        $this->data['page']->title = 'Settings &rsaquo; Authentication';

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

        //  Load view
        Helper::loadView('index');
    }
1238188
public function login()
    {
        if(Sentry::check()){
            Response::redirect($this->siteUrl('admin'));
        }else{
            $this->data['redirect'] = (Input::get('redirect')) ? base64_decode(Input::get('redirect')) : '';
            View::display('admin/login.twig', $this->data);
        }
    }
562102
public function run()
    {
        // php artisan db:seed --class="PermissionsTableSeeder"
        $permissions = [
            [
                'name' => 'manage_users',
            ],
            [
                'name' => 'manage_pages',
            ],
            [
                'name' => 'access_admin',
            ],
        ];

        // Only add new
        $allPermissions = Permission::all()->pluck('name')->toArray();

        foreach ($permissions as $permission) {
            if (! in_array($permission['name'], $allPermissions)) {
                Permission::create($permission);
            }
        }
    }
305498
public function loginAction() {
        // Do not cache login page
        $this->_helper->cache->setNoCacheHeaders($this->getResponse());

        $this->view->title = __('login page title');
        $this->view->description = __('login page description');

        // allow callers to set a targetUrl via the request
        if ($targetUrl = $this->_getSubmittedTargetUrl()) {
            Garp_Auth::getInstance()->getStore()->targetUrl = $targetUrl;
        }

        $authVars = Garp_Auth::getInstance()->getConfigValues();
        // self::processAction might have populated 'errors' and/or 'postData'
        if ($this->getRequest()->getParam('errors')) {
            $this->view->errors = $this->getRequest()->getParam('errors');
        }
        if ($this->getRequest()->getParam('postData')) {
            $this->view->postData = $this->getRequest()->getParam('postData');
        }
    }
308070
private function login()
    {
        if ($this->loggedIn) {
            return;
        }

        if (array_key_exists('rsakey', $this->sshConfig)) {
            $this->loginWithRsaKey();
        } elseif (array_key_exists('password', $this->sshConfig)) {
            $this->loginWithPassword();
        }

        $this->loggedIn = $this->validate();
    }
783062
public function loginWith()
    {
        $providerName = $_REQUEST["provider"];
        $redirect = $_GET['redirect'];

        $userProfile = $this->getAuthProvider()->authenticate($providerName);

        if ($userProfile instanceof Exception) {
            $this->getView()->set('exception', $userProfile);
        } else {
            $userExist = User_Logins::instance()->getUserByProvider($providerName, $userProfile->identifier);

            if (!$userExist) {
                $this->redirect(
                    $this->getModelManager()->getOAuthLinkURL([
                        'provider' => $providerName,
                        'redirect' => $redirect
                    ]));
            }

            $userExist->doAuthentication();

            $this->afterLoginRedirect();
        }
    }
1006781
def login_required(self, fresh=False, redirect_to=None):
        
        if not self.logged_in() or (fresh and not self.login_manager.login_fresh()):
            if redirect_to:
                resp = redirect(redirect_to)
            else:
                resp = self.login_manager.unauthorized()
            current_context.exit(resp, trigger_action_group="missing_user")
1187375
public function actionForgottenPassword(): void
	{
		$session = $this->getSession('cms/forgottenPassword');
		if ($session->count >= self::MAX_TRY) {
			$this->flashNotifier->warning('cms.user.restorePasswordDisabledForHour');
			$this->redirect(":{$this->module}:Sign:in");
		}
	}
366583
final protected function onAuth()
    {
        $authService = $this->getAuthService();

        $this->authManager->setAuthService($authService);

        if ($this->authActive === true) {
            if ($authService->isLoggedIn()) {
                $this->onSuccess();
            } else {
                $this->onFailure();
            }
        }

        // Now handle RBRAC if present
        if ($this->hasRbacRules()) {
            // Check if provided user has enough privileges
            if (!$this->hasRight($authService->getRole())) {
                $this->onNoRights();
            }
        }
    }
480797
public function login()
    {

        // initialize the flag for the successfull login
        $this->loginOk = false;

        // array containing the username and password from the user's input
        list ($this->username, $password) = $this->getUsernameAndPassword();

        // query whether or not password AND username are set
        if ($this->username === null && $password === null) {
            $this->identity = $this->unauthenticatedIdentity;
        }

        // try to create a identity based on the given username
        if ($this->identity === null) {
            try {
                $this->identity = $this->createIdentity($this->username);
            } catch (\Exception $e) {
                throw new LoginException(
                    sprintf('Failed to create principal: %s', $e->getMessage())
                );
            }
        }

        // connect to the LDAP server
        $ldapConnection = $this->ldapConnect();

        // replace the placeholder  with the actual username of the user
        $this->baseFilter = preg_replace('/\{0\}/', "$this->username", $this->baseFilter);

        // try to load the user from the LDAP server
        $search = ldap_search($ldapConnection, $this->baseDN, $this->baseFilter);
        $entry = ldap_first_entry($ldapConnection, $search);
        $this->userDN = ldap_get_dn($ldapConnection, $entry);

        // query whether or not the user is available
        if (!isset($this->userDN)) {
            throw new LoginException('User not found in LDAP directory');
        }

        // bind the authenticating user to the LDAP directory
        if ((ldap_bind($ldapConnection, $this->userDN, $password)) === false) {
            throw new LoginException('Username or password wrong');
        }

        // query whether or not password stacking has been activated
        if ($this->getUseFirstPass()) {
            // add the username and password to the shared state map
            $this->sharedState->add(SharedStateKeys::LOGIN_NAME, $this->username);
            $this->sharedState->add(SharedStateKeys::LOGIN_PASSWORD, $this->credential);
        }

        // set the login flag to TRUE and return
        return $this->loginOk = true;
    }
744681
protected static function login() :void {
		
		// look for users with this login
		$account = \Models\Accounts::getFirstEnabledWithLogin(
			Request::post( Config::get('security', 'login') )
		);
		// if the account does not exist/is not found
		if(!$account) {
			// we deny access
			self::refuse('Account does not exist or is disabled'); 
		}
		// if the account has been forced by that ip recently
		if($account->hasFailedLoginAttemptsRecentFrom(self::getSafeRemoteAddress())) {
			// extend the lock on the account
			$account->extendLoginBan();
			// refuse access
			self::refuse('Please wait '.Config::get('security', 'waiting_duration').' seconds before trying again');
		}
		// if the account has expired
		if($account->hasItsValidityExpired()) {
			// register that failure
			$account->registerFailedLoginAttemptFrom(self::getSafeRemoteAddress(), self::getSafeUserAgent());
			// refuse access
			self::refuse("Your account has expired, it was valid until {$account->get('account_expiration_date')}");	
		}
		// if the posted password doesn't match the account's password
		if(!$account->hasThisPassword(Request::post(Config::get('security', 'password')))) {
			// register that failure
			$account->registerFailedLoginAttemptFrom(self::getSafeRemoteAddress(), self::getSafeUserAgent());
			// refuse access
			self::refuse('Wrong password');
		}
		// if we failed to open a session
		if(!$account->tryOpeningSession()) {
			// we report that something is wrong
			self::refuse('Your session failed to open, make sure your browser accepts cookies', 500);
		}
		// then session has been opened
		else {
			// log the loggin action
			Logger::info("Account {$account->get('login')} has logged in");
			// put the user inside of us
			self::$_account = $account;
			// set the most basic authentication block as being true/passed
			self::$_granted = true;
			// if we have an url in the session, redirect to it (and remove it)
			!Session::has('previously_requested_url') ?: self::redirectToThePreviouslyRequestedUrl();
		}
		
	}
1209889
public function run(): void
    {
        // http://stackoverflow.com/q/1598411
        $list = [
            ['name' => 'Super Admin', 'slug' => HCRoleRepository::ROLE_SA], // Manage everything
            ['name' => 'Project Admin', 'slug' => HCRoleRepository::ROLE_PA], // Manage most aspects of the site
            ['name' => 'User', 'slug' => HCRoleRepository::ROLE_U], // Average Joe
        ];

        foreach ($list as $roleData) {
            $role = $this->repository->findOneBy(['slug' => $roleData['slug']]);

            if (!$role) {
                $this->repository->create($roleData);
            }
        }
    }
556082
private function login()
    {
        if (empty($this->host)) {
            throw new RuntimeException('no host to connect to');
        }

        $old  = error_reporting(0);
        $link = $this->isSecure
              ? ftp_ssl_connect($this->host, $this->port)
              : ftp_connect($this->host, $this->port);

        if (!$link) {
            error_reporting($old);
            throw new RuntimeException(sprintf('unable to connect to ftp server %s', $this->host));
        }

        $this->connection = $link;
        if (!ftp_login($this->connection, $this->user, $this->password)) {
            error_reporting($old);
            throw new RuntimeException(
                sprintf('authentication failed for %s@%s', $this->user, $this->host)
            );
        }
        // set passive mode if needed
        $this->pasv($this->passive);
        error_reporting($old);
    }
962319
public function login() {
        if ($this->request->is('post')) {
            $user = $this->Auth->identify();
            if ($user) {
                $this->Auth->setUser($user);
                return $this->redirect($this->Auth->redirectUrl());
            }
            $this->Flash->error(__('Your username or password is incorrect.'));
        }

        // Set signin layout from Builder.Layout
        $this->viewBuilder()->layout('signin');
        // Use the layout without Template 
        $this->render(false);
    }
745539
public function actionLogin()
	{
		$model=Yii::createComponent('gii.models.LoginForm');

		// collect user input data
		if(isset($_POST['LoginForm']))
		{
			$model->attributes=$_POST['LoginForm'];
			// validate user input and redirect to the previous page if valid
			if($model->validate() && $model->login())
				$this->redirect(array('index'));
		}
		// display the login form
		$this->render('login',array('model'=>$model));
	}
1124187
public function logAccess()
    {
        $this->db->executeUpdate(
                "update nb_site_user "
                 . "set nb_site_user_last_login_datetime=now() "
               . "where nb_site_id=%site_id\$d "
                 . "and nb_role_id=%role_id\$d "
                 . "and nb_user_id=%user_id\$d",
                array(
                    'site_id' => $this->getValue('nb_site_id'),
                    'role_id' => $this->getValue('nb_role_id'),
                    'user_id' => $this->getValue('nb_user_id')
                )
        );
    }