Login to server using rsa key-file.

@return bool

@throws SshLoginException
501068
private function loginWithRsaKey()
    {
        $key = new RSA();
        $password = $this->sshConfig['rsakey']['password'];
        if ($password) {
            if (!is_string($password)) {
                $password = $this->askForPassword(
                    sprintf('Password for file "%s": ', $this->sshConfig['rsakey']['file'])
                );
            }

            $key->setPassword($password);
        }

        $key->loadKey(file_get_contents($this->sshConfig['rsakey']['file']));
        if (!$this->ssh->login($this->sshConfig['username'], $key)) {
            throw new SshLoginException($this->name);
        }

        return true;
    }
662985
public function login()
    {
        if (!$this->authenticate())
            return false;

        if($this->_identity->errorCode===RemoteUserIdentity::ERROR_NONE)
		{
            Yii::app()->user->logout();
			return Yii::app()->user->login($this->_identity,3600*24);
		}
		else
			return false;

    }
549524
public function loginSuccess()
    {
        $this->userID = (int) $this->kontakt->getMyKey();
        $this->setUserLogin($this->kontakt->getDataValue($this->loginColumn));
        $this->logged = true;
        $this->addStatusMessage(sprintf(_('Sign in %s all ok'), $this->userLogin),
            'success');

        return true;
    }
115564
public function authenticate()
    {

        $signer = new RequestSigner();
        $signer->setProvider('USF');
        $authenticator = new RequestAuthenticator($signer, $this->_timeout);

        $key = $authenticator->authenticate($this->_requestWrapper, $this->_keyLoader);

        if ($key) {
            $this->principal = "[HMAC]".$key->getId();
            $this->attributes = [];
            return true;
        }

        return false;

    }
812922
public static function httpAuthenticate() {
		try { 
			static::httpLogin();
			return true;
		} catch( NotFoundException $e ) {
			if( Config::get('httpauth_autocreate') ) {
				$user = static::httpCreate();
				$user->login();
				return true;
			}
		} catch( UserException $e ) { }
		return false;
	}
348290
protected function getAuthForLogin()
    {
        if ($this->useAgent()) {
            return $this->getAgent();
        }

        // If a "key" was specified in the auth credentials, we will load it into a
        // secure RSA key instance, which will be used to connect to the servers
        // in place of a password, and avoids the developer specifying a pass.
        elseif ($this->hasRsaKey()) {
            return $this->loadRsaKey($this->auth);
        }

        // If a plain password was set on the auth credentials, we will just return
        // that as it can be used to connect to the server. This will be used if
        // there is no RSA key and it gets specified in the credential arrays.
        elseif (isset($this->auth['password'])) {
            return $this->auth['password'];
        }

        throw new \InvalidArgumentException('Password / key is required.');
    }
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();
    }
794677
private function login()
    {
        if (isset($this->config['connection_password'])) {
            $this->send(Response::pass($this->config['connection_password']));
        }

        $this->send(Response::nick($this->config['nick']));
        $this->send(Response::user(
            $this->config['username'],
            $this->config['realname']
        ));

        if (isset($this->config['password'])) {
            $this->send(Response::msg(
                'NickServ',
                'IDENTIFY ' . $this->config['password']
            ));
        }
    }
113720
public function run()
	{
		// Login to the remote server
		$this->printTaskInfo('Logging into remote server - <info>ssh://'.$this->sshUser.'@'.$this->sshHost.'/</info>');
		$ssh = new SFTP($this->sshHost);

		// Do we use password or a key
		if (file_exists($this->sshKey) && empty($this->sshPass))
		{
			$key = new RSA();
			$key->loadKey(file_get_contents($this->sshKey));
			if (!$ssh->login($this->sshUser, $key))
			{
				throw new RuntimeException
				(
					'Failed to login via SSH using Key Based Auth.'
				);
			}
		}
		else
		{
			if (!$ssh->login($this->sshUser, $this->sshPass))
			{
				throw new RuntimeException
				(
					'Failed to login via SSH using Password Based Auth.'
				);
			}
		}

		// Create our dump filename
		$dump_name = $this->remoteDbName.'_'.time();

		// Create our dump on the remote server
		$cmd = 'mysqldump '.
			'-h'.$this->remoteDbHost.
			' -u'.$this->remoteDbUser.
			' '.(empty($this->remoteDbPass) ? '' : '-p'.$this->remoteDbPass).
			' '.$this->remoteDbName.' > /tmp/'.$dump_name.'.sql'
		;
		$this->printTaskInfo('Dumping db on remote server - <info>'.$cmd.'</info>');
		$results = $ssh->exec($cmd);
		if ($ssh->getExitStatus() > 0)
		{
			throw new RuntimeException
			(
				'Failed to create dump on remote server. '.
				$results
			);
		}

		// Compressing dump
		$cmd = 'gzip /tmp/'.$dump_name.'.sql';
		$this->printTaskInfo('Compressing dump on remote server - <info>'.$cmd.'</info>');
		$results = $ssh->exec($cmd);
		if ($ssh->getExitStatus() > 0)
		{
			throw new RuntimeException
			(
				'Failed to compress dump on remote server. '.
				$results
			);
		}

		// Copy it down locally
		$this->printTaskInfo('Transfering dump to local.');
		$temp_dump_name = tempnam(sys_get_temp_dir(), 'dump');
		$temp_dump = $temp_dump_name.'.sql.gz';
		if (!$ssh->get('/tmp/'.$dump_name.'.sql.gz', $temp_dump))
		{
			throw new RuntimeException('Failed to download dump.');
		}

		// Remove the dump from the remote server
		$this->printTaskInfo('Removing dump from remote server - <info>rm /tmp/'.$dump_name.'.sql.gz</info>');
		if (!$ssh->delete('/tmp/'.$dump_name.'.sql.gz'))
		{
			throw new RuntimeException('Failed to delete dump on remote server.');
		}

		// Import the dump locally
		if (
			!$this->taskImportSqlDump($temp_dump)
				->host($this->localDbHost)
				->user($this->localDbUser)
				->pass($this->localDbPass)
				->name($this->localDbName)
			->run()->wasSuccessful()
		){
			throw new RuntimeException('Failed to import dump on local server.');
		}

		$this->printTaskInfo('Deleting dump locally.');
		unlink($temp_dump); unlink($temp_dump_name);

		// If we get to here assume everything worked
		return Result::success($this);
	}
173713
protected function getAuthForLogin()
	{
		// If a "key" was specified in the auth credentials, we will load it into a
		// secure RSA key instance, which will be used to connect to the servers
		// in place of a password, and avoids the developer specifying a pass.
		if ($this->hasRsaKey())
		{
			return $this->loadRsaKey($this->auth);
		}

		// If a plain password was set on the auth credentials, we will just return
		// that as it can be used to connect to the server. This will be used if
		// there is no RSA key and it gets specified in the credential arrays.
		elseif (isset($this->auth['password']))
		{
			return $this->auth['password'];
		}

		throw new \InvalidArgumentException('Password / key is required.');
	}
293406
public function login() : string {
		$token = bin2hex(random_bytes(64));
		$loginHash = password_hash($token, PASSWORD_BCRYPT);

		$stmt = $this->db->prepare(
			"INSERT INTO sessions (user_id, login_hash, api_hash) " .
			"VALUES (?, ?, NULL) " .
			"ON DUPLICATE KEY UPDATE login_hash=?;"
		);
		$stmt->bind_param("iss",
			$this->user->id, $loginHash, $loginHash);
		$stmt->execute();
		$this->db->commit();

		return $token;
	}
1311818
public function loginByRememberMe(): bool {
		
		// build the cookie name
		$cookieName = static::getRememberMeCookieName();

		// check if cookie exists
		if (!isset($_COOKIE[$cookieName])) {
			return FALSE;
		}
			
		// try to unserialize the cookie content
		$content = unserialize($_COOKIE[$cookieName]);
		
		// cookie content is not unserializable
		if (FALSE === $content) {
			return FALSE;
		}

		// check if content exists and RememberMe length
		if (isset($content[0]) and isset($content[1]) and 32==strlen($content[1])) {
			
			// try to load user
			$user = static::getByRememberMe($content[1]);
			
			// if user exists, return it
			if (is_a($user, 'Pair\User')) {
				$user->createSession($content[0]);
				$user->renewRememberMe();
				return TRUE;
			}
		
		}
		
		return FALSE;
	
	}
247542
public function loginAction()
    {
        if ($user = $this->identity()) {
            return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute());
        }
        
        $user = new User;
        $form = $this->getUserFormHelper()->createUserForm($user, 'login');
        $messages = null;
        if ($this->getRequest()->isPost()) {
            $form->setValidationGroup('usernameOrEmail', 'password', 'rememberme', 'csrf', 'captcha');
            $form->setData($this->getRequest()->getPost());
            if ($form->isValid()) {
                $data = $form->getData();
                $authService = $this->getServiceLocator()->get('Zend\Authentication\AuthenticationService');
                $adapter = $authService->getAdapter();
                $usernameOrEmail = $this->params()->fromPost('usernameOrEmail');

                try {
                    $user = $this->getEntityManager()->createQuery("SELECT u FROM CsnUser\Entity\User u WHERE u.email = '$usernameOrEmail' OR u.username = '$usernameOrEmail'")->getResult(\Doctrine\ORM\Query::HYDRATE_OBJECT);
                    $user = $user[0];
                    
                    if(!isset($user)) {
                        $message = 'The username or email is not valid!';
                        return new ViewModel(array(
                            'error' => $this->getTranslatorHelper()->translate('Your authentication credentials are not valid'),
                            'form'	=> $form,
                            'messages' => $messages,
                            'navMenu' => $this->getOptions()->getNavMenu()
                        ));
                    }
                    
                    if($user->getState()->getId() < 2) {
                        $messages = $this->getTranslatorHelper()->translate('Your username is disabled. Please contact an administrator.');
                        return new ViewModel(array(
                            'error' => $this->getTranslatorHelper()->translate('Your authentication credentials are not valid'),
                            'form'	=> $form,
                            'messages' => $messages,
                            'navMenu' => $this->getOptions()->getNavMenu()
                        ));
                    }

                    $adapter->setIdentityValue($user->getUsername());
                    $adapter->setCredentialValue($this->params()->fromPost('password'));

                    $authResult = $authService->authenticate();
                    if ($authResult->isValid()) {
                        $identity = $authResult->getIdentity();
                        $authService->getStorage()->write($identity);
                        
                        if ($this->params()->fromPost('rememberme')) {
                            $time = 1209600; // 14 days (1209600/3600 = 336 hours => 336/24 = 14 days)
                            $sessionManager = new SessionManager();
                            $sessionManager->rememberMe($time);
                        }

                        return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute());
                    }
                    
                    foreach ($authResult->getMessages() as $message) {
                      $messages .= "$message\n";
                    }
                } catch (\Exception $e) {
                    return $this->getServiceLocator()->get('csnuser_error_view')->createErrorView(
                        $this->getTranslatorHelper()->translate('Something went wrong during login! Please, try again later.'),
                        $e,
                        $this->getOptions()->getDisplayExceptions(),
                        $this->getOptions()->getNavMenu()
                    );
                }
            }
        }
        
        return new ViewModel(array(
            'error' => $this->getTranslatorHelper()->translate('Your authentication credentials are not valid'),
            'form'	=> $form,
            'messages' => $messages,
            'navMenu' => $this->getOptions()->getNavMenu()
        ));
    }
996702
public function connect()
    {
        $func = $this->ssl ? 'ftp_ssl_connect' : 'ftp_connect';
        $this->_stream = $func($this->_host, $this->_port, $this->_timeout);

        if (!$this->_stream) {
            $this->error = 'Failed to connect '.$this->_host.'.';

            return false;
        }

        if (\ftp_login($this->_stream, $this->_user, $this->_pwd)) {
            \ftp_pasv($this->_stream, (bool)$this->passive);

            $this->system_type = \ftp_systype($this->_stream);

            return true;
        }

        $this->error = 'Failed to connect to '.$this->_host.' (login failed)';

        return false;
    }
476235
protected function doLogin() {
    if ($this->user) {
      $request = ObjectFactory::getNewInstance('request');
      $request->setAction('login');
      $request->setValues([
        'login' => $this->user['login'],
        'password' => $this->user['password']
      ]);
      $response = $this->doRemoteCall($request, true);
      if ($response->getValue('success')) {
        $this->sessionId = $response->getValue('sid');
        return true;
      }
    }
    else {
      throw new \RuntimeException("Remote user required for remote call.");
    }
  }
110499
protected function checkLogin()
    {
        $pass = $this->doc->__get("password");
        if($pass){
            if(session('pass') === md5($pass)){
                return true;
            }else{
                return false;
            }
        }else{
            return true;
        }
    }
892170
public function loginApplication()
    {
        $request = [
            'auth' => [
                $this->applicationKey,
                $this->applicationSecret,
            ],
            'headers' => [
                'Content-Type'  => 'application/json',
                'Accept'        => 'application/json',
            ],
            'json'  => [
                'application_bundle' => '',
            ],
        ];

        $url = $this->getRequestUrl().'/auth/login/application';

        $response = $this->getHttpClient()->post($url, $request);
        $response = json_decode($response->getBody());

        $this->connectionToken = $response->connection->token;

        return $this->connectionToken;
    }