TODO

@param null $username
@param null $password
@param bool $encrypt
@return bool
516096
public function processLogin($username = null, $password = null, $encrypt = true)
    {
        if ($username === null && isset($_POST['username'])) {
            $username = $_POST['username'];
        }
        if ($password === null && isset($_POST['password'])) {
            $password = $_POST['password'];
        }
        if (isset($username) && isset($password)) {
            $this->csrf();
            $user = self::instanceUser(null);
            $db = $this->getDb();
            $username = $db->escape_string($username); // Para evitar inyecciones SQL
            if ($encrypt) {
                $password = $user->encrypt($password);
            }
            $user = $user->getByUserPassword($username, $password);
            if ($user) {
                $this->user = Model::newInstance('User', $user);
                if (!$this->user->disabled) {
                    $this->user->lastlogin = now();
                    $this->user->save();

                    Session::set($this->session_key, array($username, $password));
                    Events::dispatch('onLoginSuccess', array('user' => $this->user));
                    if (isset($_REQUEST['remember']) && $_REQUEST['remember']) {
                        setcookie($this->session_key, serialize(Session::get($this->session_key)),
                            time() + 60 * 60 * 24 * 30, '/');
                    }
                    $this->redirectLogin();
                    return true;

                } else {
                    $this->addMessage('Este usuario está desactivado', 'danger');
                }
            } else {
                $this->addMessage('Usuario o contraseña incorrecta', 'danger');
            }
        }
        return false;
    }
575854
static public function encrypt($plaintextFileName, $ciphertextFileName, $key_name = null) {
        $kms = self::getService();
        if (is_null($key_name)) {
            $key_name = self::getDefaultKeyName();
        }

        // Use the KMS API to encrypt the text.
        $encoded = base64_encode(file_get_contents($plaintextFileName));
        $request = new \Google_Service_CloudKMS_EncryptRequest();
        $request->setPlaintext($encoded);
        $response = $kms->projects_locations_keyRings_cryptoKeys->encrypt(
            $key_name,
            $request
        );

        // Write the encrypted text to a file.
        file_put_contents($ciphertextFileName, base64_decode($response['ciphertext']));
        Util::cmdline("\tSaved encrypted text to $ciphertextFileName with key $key_name");
        return true;
    }
87699
public function encrypt($text, $key = null)
    {
        if (null === $key) {
            $key = $this->getEncryptKey();
        }

        $ivSize = $this->getMsCryptIvSize();
        $iv     = mcrypt_create_iv($ivSize, MCRYPT_DEV_RANDOM);

        $cipherText = mcrypt_encrypt(
            $this->getMcryptCipher(),
            $key,
            $text,
            $this->getMcryptMode(),
            $iv
        );

        $cipherText = $iv.$cipherText;

        return base64_encode($cipherText);
    }
620127
public void encrypt(final String userName, final String password) {
        encrypt(userName, password.getBytes(Charsets.UTF_8), MessageEncryption.NONE);
    }
1170826
public static @Nullable byte[] encrypt(EncryptionKey encryptionKey, @Nullable String value) throws NoSuchPaddingException,
	                                                                                                   InvalidKeyException,
	                                                                                                   NoSuchAlgorithmException,
	                                                                                                   IllegalBlockSizeException,
	                                                                                                   BadPaddingException,
	                                                                                                   InvalidAlgorithmParameterException,
	                                                                                                   EncryptionException {
		return value != null ? encrypt(encryptionKey, value.getBytes()) : null;
	}
761506
public function checkUserCredentials($username, $password)
    {
        if ($user = $this->getUser($username)) {
            return $this->checkPassword($user, $password);
        }

        return false;
    }
942896
public function getOpenSslEncryptor(int $cipher, string $password): OpenSslEncryptor {
        if (false === extension_loaded('openssl')) {
            throw new \Exception('OpenSSL Extension not available');
        }
        $encryptor = new OpenSslEncryptor($cipher, $password);
        if (false === $encryptor->isEncryptionCipherSupported($cipher)) {
            throw new \Exception('Trying to use unsupported encryption cipher');
        }
        return $encryptor;
    }
1338689
public function login(string $username, string $password)
    {
        $this->userInfo = $this->makeRequest('POST', 'login', compact('username', 'password'));

        if (!isset($this->userInfo['error']) && isset($this->userInfo['data']['id'])) {
            return true;
        }

        return false;
    }
1090226
function encrypt($text, $keys, $sign_key = null)
    {
        try {
            foreach ($keys as $key) {
                $this->gpg->addEncryptKey($key->reference);
            }

            if ($sign_key) {
                $this->gpg->addSignKey($sign_key->reference, $sign_key->password);

                $res     = $this->gpg->encryptAndSign($text, true);
                $sigInfo = $this->gpg->getLastSignatureInfo();

                $this->last_sig_algorithm = $sigInfo->getHashAlgorithmName();

                return $res;
            }

            return $this->gpg->encrypt($text, true);
        }
        catch (Exception $e) {
            return $this->get_error_from_exception($e);
        }
    }
1355447
public static function encryptWithPassword(
        string $plaintext,
        string $password,
        string $ad = '',
        string $format = null
    ): string {
        return self::encrypt($plaintext, $password, $ad, $format, true);
    }
978790
public static function isValidPassword($username , $password)
	{
		if ( ! self::userExists( $username ) ) return false;
		$compute = self::getPasswordHash($username , $password);

		return ( $compute === self::$auth['users'][$username]['pwd'] );
	}
788754
public function login($username = null, $password = null)
    {
        $this->_username = null !== $username ? $username : $this->_username;
        $this->_password = null !== $password ? $password : $this->_password;

        if (null === $this->_ssh_resource) {
            throw new TransportException(sprintf('None SSH connection available.'));
        }

        if (null === $this->_ssh_key_pub) {
            if (false === ssh2_auth_password($this->_ssh_resource, $this->_username, $this->_password)) {
                throw new TransportException(sprintf('Could not authenticate with username %s.', $this->_username));
            }
        } else {
            if (false === ssh2_auth_pubkey_file($this->_ssh_resource, $this->_username, $this->_ssh_key_pub, $this->_ssh_key_priv, $this->_ssh_key_pass)) {
                throw new TransportException(sprintf('Could not authenticate with keyfile %s.', $this->_keyfile));
            }
        }

        if (false === $this->_sftp_resource = ssh2_sftp($this->_ssh_resource)) {
            throw new TransportException("Could not initialize SFTP subsystem.");
        }

        return $this;
    }
867190
private static function getPasswordHash($username , $password)
	{
		return sha1( self::getSecurityToken() . $username . self::getGenerated() . $password );
	}
651972
public function authenticate($username, $password) {
        $success = isset($this->options["users"][$username]) && $this->options["users"][$password] === $password;

        if (!$success) {
            $this->error = new \SlimPower\Authentication\Error();
            return null;
        } else {
            return array('user' => $username);
        }
    }
1189030
public function login($username, $password)
  {
    $this->execute("login", array("client_login_name" => $username, "client_login_password" => $password));
    $this->whoamiReset();

    $crypt = new TeamSpeak3_Helper_Crypt($username);

    $this->setStorage("_login_user", $username);
    $this->setStorage("_login_pass", $crypt->encrypt($password));

    TeamSpeak3_Helper_Signal::getInstance()->emit("notifyLogin", $this);
  }
1036900
public function password($password = null)
    {
        if (func_num_args() === 0) {
            return $this->_password;
        }
        $this->_password = $password ?: null;
        return $this;
    }
901978
protected function readPayload($encrypt)
	{
		if (!$encrypt && isset($_GET['jfpayload'])) {
			ob_start();
			$payload = json_decode(trim(base64_decode($_GET['jfpayload'])));
			ob_end_clean();
		} else if ($encrypt && isset($_POST['jfpayload'])) {
			$payload = Api::decrypt($this->key , $_POST['jfpayload']);
		}
		if (isset($payload) && is_array($payload)) {
			$this->payload = $payload;
			return true;
		}
		return false;
	}