@param string $clearTextPassword
@param string $salt
@param int $algorithm
@param array $options

@return bool|string
970865
static public function userPasswordGenerator($clearTextPassword, $salt, $algorithm = PASSWORD_BCRYPT, array $options = []) {
        return password_hash($salt . $clearTextPassword, $algorithm, $options);
    }
1286647
@Override
    public String encryptPassword(String cleartext) {
        String encrypted = sha256Encryptor.encryptPassword(cleartext);
        if (encrypted.endsWith("\n")) {
            encrypted = encrypted.substring(0, encrypted.length() - 1);
        }
        encrypted = SHA256_PREFIX.concat(encrypted);
        return encrypted;
    }
626914
protected function protect($password, $salt = null)
    {
        $salt = isset($salt)
            ? $salt
            : $this->salt;

        return $password . $salt;
    }
32780
protected function getSalt()
    {
        $salt = $this->getConfig()->get('passwordSalt');
        if (!isset($salt)) {
            throw new Error('Option "passwordSalt" does not exist in config.php');
        }

        $salt = $this->normalizeSalt($salt);

        return $salt;
    }
1159525
public function encrypt(string $plainText, ContentEncryptionKey $contentEncryptionKey, Nonce $nonce, Salt $salt, PublicKey $senderPublicKey) : Cipher
    {
        return $this->crypt->encrypt($plainText, $contentEncryptionKey, $nonce, $salt, $senderPublicKey);
    }
302983
public String encrypt64( final String clearText, final String password )
    throws PlexusCipherException
    {
        try
        {
            byte[] clearBytes = clearText.getBytes( STRING_ENCODING );
    
            byte[] salt = getSalt( SALT_SIZE );
            
            Cipher cipher = createCipher( password.getBytes( STRING_ENCODING ), salt, Cipher.ENCRYPT_MODE  );
    
            byte [] encryptedBytes = cipher.doFinal( clearBytes );
            
            int len = encryptedBytes.length;
            
            byte padLen = (byte) ( CHUNK_SIZE - (SALT_SIZE + len + 1) % CHUNK_SIZE );
            
            int totalLen = SALT_SIZE + len + padLen + 1;
            
            byte [] allEncryptedBytes = getSalt( totalLen );
            
            System.arraycopy( salt, 0, allEncryptedBytes, 0, SALT_SIZE );
            
            allEncryptedBytes[ SALT_SIZE ] = padLen;
            
            System.arraycopy( encryptedBytes, 0, allEncryptedBytes, SALT_SIZE + 1, len );
            
            byte [] encryptedTextBytes = Base64.encodeBase64( allEncryptedBytes );
            
            String encryptedText = new String( encryptedTextBytes, STRING_ENCODING );
    
            return encryptedText;
        }
        catch( Exception e)
        {
            throw new PlexusCipherException(e);
        }
    }
593372
public static function decode( $data, $salt = null ) {
		
		if ( is_null( $salt ) ) {
			$salt = static::$default_salt;
		}
		
		return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($salt), base64_decode($data), MCRYPT_MODE_CBC, md5(md5($salt))), "\0");
	}
1320067
public function validatePassword($plaintext, $hashed)
	{
		// Use the password extension if able
		if (version_compare(PHP_VERSION, '7.2', '>=') && \defined('PASSWORD_ARGON2I'))
		{
			return password_verify($plaintext, $hashed);
		}

		// Use the sodium extension (PHP 7.2 native or PECL 2.x) if able
		if (\function_exists('sodium_crypto_pwhash_str_verify'))
		{
			$valid = sodium_crypto_pwhash_str_verify($hashed, $plaintext);
			sodium_memzero($plaintext);

			return $valid;
		}

		// Use the libsodium extension (PECL 1.x) if able
		if (\extension_loaded('libsodium'))
		{
			$valid = \Sodium\crypto_pwhash_str_verify($hashed, $plaintext);
			\Sodium\memzero($plaintext);

			return $valid;
		}

		throw new \LogicException('Argon2i algorithm is not supported.');
	}
838835
public function generatePasswordHash(string $password, string $salt = ''): string
    {
        $password = ($salt ?: self::$salt) . trim($password);

        $options = [
            'cost' => 12,
        ];

        return password_hash($password, PASSWORD_BCRYPT, $options);
    }
923283
public function encryptPassword($password, $salt = null)
    {
        if (!is_string($this->password_encryption) && is_callable($this->password_encryption)) {
            $e = $this->password_encryption;

            return $e($password, $salt);
        }
        if ($this->password_encryption) {
            $this->debug("Encrypting password: '$password' with ".$this->password_encryption.' salt='.$salt);
        }
        switch ($this->password_encryption) {
            case null:
                return $password;
            case 'php':
                // returns false on failure
                return password_hash($password, $this->hash_algo, $this->hash_options);
            case 'sha256/salt':
                if ($salt === null) {
                    throw $this->exception(
                        'sha256 requires salt (2nd argument to encryptPassword and is normaly an email)'
                    );
                }
                $key = $this->app->getConfig('auth/key', $this->app->name);
                if ($this->password_encryption) {
                    $this->debug('Using key '.$key);
                }

                return hash_hmac('sha256', $password.$salt, $key);
            case 'sha1':
                return sha1($password);
            case 'md5':
                return md5($password);
            case 'rot13':
                return str_rot13($password);
            default:
                throw $this->exception('No such encryption method')
                    ->addMoreInfo('encryption', $this->password_encryption);
        }
    }
1269758
protected function saltPassword($password)
    {
        if (isset($this->metaData['salt'])) {
            $salt = $this->metaData['salt'];
        } else {
            $salt = $this->generateSalt();
        }
        
        return $salt . $password;
    }
227368
public static function generateSaltedMd5($clearString)
    {
        $salt = substr(md5(rand() . Utility\Algorithms::generateRandomString(23)), 0, rand(6, 10));
        return (md5(md5($clearString) . $salt) . ',' . $salt);
    }
674664
public function validatePassword($plaintext, $hashed)
	{
		// Use the password extension if able
		if (version_compare(PHP_VERSION, '7.3', '>=') && \defined('PASSWORD_ARGON2ID'))
		{
			return password_verify($plaintext, $hashed);
		}

		throw new \LogicException('Argon2id algorithm is not supported.');
	}
408589
public function generateKey(array $options = array())
	{
		// Create the new encryption key object.
		$key = new Key($this->keyType);

		// Generate an initialisation vector based on the algorithm.
		$key->public = mcrypt_create_iv(mcrypt_get_iv_size($this->type, $this->mode));

		// Get the salt and password setup.
		$salt = (isset($options['salt'])) ? $options['salt'] : substr(pack("h*", md5(mt_rand())), 0, 16);
		$password = (isset($options['password'])) ? $options['password'] : 'J00ml4R0ck$!';

		// Generate the derived key.
		$key->private = $this->pbkdf2($password, $salt, mcrypt_get_key_size($this->type, $this->mode));

		return $key;
	}
329754
public static function comparePasswords($passhash, $password)
	{
		if (empty($passhash) || empty($password))
		{
			return false;
		}

		preg_match("/^\s*(\{(.*)\}\s*|)((.*?)\s*:\s*|)(.*?)\s*$/", $passhash, $matches);

		$encryption = strtolower($matches[2]);

		if (empty($encryption))
		{
			// Joomla
			$encryption = "md5-hex";

			if (!empty($matches[4]))
			{
				// Joomla 1.5
				$crypt = $matches[4];
				$salt  = $matches[5];
			}
			else
			{
				// Joomla 1.0
				$crypt = $matches[5];
				$salt  = '';
			}
		}
		else
		{
			$salt  = $matches[4];
			$crypt = $matches[5];
		}

		if ($encryption == 'md5')
		{
			$encryption = "md5-base64";
		}
		else if ($encryption == 'crypt')
		{
			preg_match('/\$([[:alnum:]]{1,2})\$[[:alnum:]]{8}\$/', $passhash, $parts);
			$salt = $parts[0];

			switch ($parts[1])
			{
				case '6':
				default:
					$encryption = 'crypt-sha512';
					break;
			}
		}

		if (empty($salt) && ($encryption == 'ssha'))
		{
			$salt = substr(base64_decode(substr($crypt, -32)), -4);
			$hashed = base64_encode(mhash(MHASH_SHA1, $password . $salt) . $salt);
		}
		else
		{
			$hashed = self::_getCryptedPassword($password, $salt, $encryption);
		}

		return ($crypt == $hashed);
	}
1273855
public static function CreateSecurePassword ($password, $key, $algorithm = self::PASSWORD_HASH_ALGORITHM) {
		return hash_hmac($algorithm, $password, $key);
	}
272289
public static function getPassword(string $string) :string {
		// get a signature using (the provided string + salt)
		return(hash(Config::get('security','algo'),
			Config::get('security','salt') . $string . Config::get('security','salt')
		));
	}