Get hashed version (this version can be stored in DB).

@param int $cost
@param string|null $salt

@return string
@throws PasswordEmptyException
@throws PasswordHashException
483643
public function getHash(int $cost = null, string $salt = null) : string
    {
        if (is_null($cost)) $cost = 10;
        if (is_null($this->rawValue)) {
            throw new PasswordEmptyException('Password value not found@' . __METHOD__);
        }
        $hash = password_hash($this->rawValue, PASSWORD_DEFAULT, ['cost' => $cost]);
        if (!$hash) {
            throw new PasswordHashException('Password hashing failed@' . __METHOD__);
        }
        return $hash;
    }
779028
public function genSalt($input = null)
    {
        if (!$input) {
            $input = $this->_getRandomBytes(16);
        }

        // Hash identifier
        $identifier = $this->_identifier;

        // Cost factor - "4" to "04"
        $costFactor  = chr(ord('0') + $this->_iterationCountLog2 / 10);
        $costFactor .= chr(ord('0') + $this->_iterationCountLog2 % 10);

        // Salt string
        $salt = $this->_encode64($input, 16);

        // $II$CC$SSSSSSSSSSSSSSSSSSSSSS
        return '$' . $identifier . '$' . $costFactor . '$' . $salt;
    }
225060
public function getPassword() : IHashedPassword
    {
        return new class implements IHashedPassword
        {
            /**
             * Gets the hashed password string.
             *
             * @return string
             */
            public function getHash() : string
            {
                // TODO: Implement getHash() method.
            }

            /**
             * Gets the hashing algorithm.
             *
             * @return string
             */
            public function getAlgorithm() : string
            {
                // TODO: Implement getAlgorithm() method.
            }

            /**
             * Gets the hashing cost factor.
             *
             * @return int
             */
            public function getCostFactor() : int
            {
                // TODO: Implement getCostFactor() method.
            }

            /**
             * Returns an associated array of the values indexed by the property names.
             *
             * This returns all properties regardless of accessibility.
             *
             * @return array
             */
            public function toArray() : array
            {
                // TODO: Implement toArray() method.
            }

            /**
             * Sets the properties of the object.
             *
             * The property types and structure are NOT validated in any way
             * and as such this should only be used for restoring object
             * state from a persistence store which is in a valid state.
             *
             * @param array $properties
             *
             * @return void
             */
            public function hydrate(array $properties)
            {
                // TODO: Implement hydrate() method.
            }
        };
    }
1035651
public static String hash(char[] password, int cost)
	{
		String salt = BCryptImpl.gensalt(cost);

		return BCryptImpl.hashpw(new String(password), salt);
	}
995256
private function checkModePbkdf2($password, $hash)
    {
        $this->cwsDebug->titleH2('Check password hash in PBKDF2 mode');
        $this->cwsDebug->labelValue('Password', $password);
        $this->cwsDebug->dump('Hash', $hash);

        $params = explode(self::PBKDF2_SEPARATOR, $hash);
        if (count($params) < self::PBKDF2_SECTIONS) {
            return false;
        }

        $algorithm = $params[self::PBKDF2_ALGORITHM_INDEX];
        $salt = $params[self::PBKDF2_SALT_INDEX];
        $ite = $params[self::PBKDF2_ITE_INDEX];
        $hash = base64_decode($params[self::PBKDF2_HASH_INDEX]);
        $this->cwsDebug->labelValue('Decoded hash', $hash);

        $checkHash = $this->getPbkdf2($algorithm, $password, $salt, $ite, strlen($hash), true);
        $this->cwsDebug->labelValue('Check hash', $checkHash);

        $result = $this->slowEquals($hash, $checkHash);
        $this->cwsDebug->labelValue('Valid?', ($result ? 'YES!' : 'NO...'));

        return $result;
    }
918297
public function generateNewKey(int $cost = self::HASH_COST)
    {
        $this->key = bin2hex(random_bytes(self::KEY_SIZE));
        $this->hash = $this->makeHash($this->key, $cost);
    }
1201753
public function verifyPasswordHash(string $password, string $hash, string $salt = ''): string
    {
        $password = ($salt ?: self::$salt) . trim($password);

        return password_verify($password, $hash);
    }
897791
protected function encrypt($value = null, $salt = '')
    {
        return $this->hasher($salt)->encode($this->findValueToSlug($value));
    }
234505
public function cryptPassword(string $password, string $salt): string
    {
        return \strtoupper(\md5(\md5($salt) . \md5($password)));
    }
104113
public function create($password)
    {
        if (!$this->salt) {
            $salt = str_replace('+', '.', base64_encode(CryptHelper::genRandomBytes(64)));
        } else {
            $salt = $this->salt;
        }

        switch ($this->type) {
            case static::MD5:
                $salt = '$1$' . $salt . '$';
                break;

            case static::SHA256:
                $cost = CryptHelper::limitInteger($this->cost, 1000);

                $salt = '$5$rounds=' . $cost . '$' . $salt . '$';
                break;

            case static::SHA512:
                $cost = CryptHelper::limitInteger($this->cost, 1000);

                $salt = '$6$rounds=' . $cost . '$' . $salt . '$';
                break;

            case static::SODIUM_ARGON2:
                return \Sodium\crypto_pwhash_str(
                    $password,
                    \Sodium\CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
                    \Sodium\CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE
                );

            case static::SODIUM_SCRYPT:
                return \Sodium\crypto_pwhash_scryptsalsa208sha256_str(
                    $password,
                    \Sodium\CRYPTO_PWHASH_SCRYPTSALSA208SHA256_OPSLIMIT_INTERACTIVE,
                    \Sodium\CRYPTO_PWHASH_SCRYPTSALSA208SHA256_MEMLIMIT_INTERACTIVE
                );

            default:
            case static::BLOWFISH:
                $salt = CryptHelper::repeatToLength($salt, 22, true);
                $cost = CryptHelper::limitInteger($this->cost, 4, 31);

                $options['cost'] = $cost;

                return password_hash($password, PASSWORD_BCRYPT, $options);
                break;
        }

        if (!function_exists('crypt')) {
            throw new \RangeException("crypt() must be loaded for Password::create method");
        }

        return crypt($password, $salt);
    }
1343143
protected function hasher($salt = '')
    {
        $salt = $salt ?: $this->slugWorkingRecord->{$this->slugDbFieldForSalt} ?: $this->slugSalt;

        if ($salt) {
            return Object::create('Milkyway\SS\Behaviours\Contracts\Slugger', $salt, $this->slugLength);
        }

        if (!$this->slugHasher) {
            $this->slugHasher = Object::create('Milkyway\SS\Behaviours\Contracts\Slugger', $salt, $this->slugLength);
        }

        return $this->slugHasher;
    }
896173
public function hash(string $password): string
    {
        if ('' === $password) {
            throw EmptyPasswordException::create();
        }

        return password_hash($password, PASSWORD_DEFAULT);
    }
847874
public static function createSubHash($string, $salt)
    {
        $context = self::createContext($string, $salt);
        $null = chr(0);
        $hash = '';
        for ($i = 0; $i < self::HASH_COUNT_STEPS; $i++) {
            $k = $i + 6;
            $j = $i + 12;
            if ($j === 16) {
                $j = 5;
            }
            $hash = $context[$i].$context[$k].$context[$j].$hash;
        }
        $hash = $null.$null.$context[11].$hash;
        $hash = base64_encode($hash);
        $hash = substr($hash, 2);
        $hash = strrev($hash);
        $hash = strtr($hash, self::BASE64_ALPHABET, self::ALPHABET);
        return $hash;
    }
81922
public function hash($password, $salt = null)
    {
        $hash_format = sprintf("$2y$%02d$", $this->cost);

        !$salt && $salt = $this->generateSalt();
        if (strlen($salt) < 22) {
            throw new \InvalidArgumentException(sprintf("Provided salt is too short: %d expecting %d", strlen($salt), 22));
        }

        $hash = $hash_format . $salt;
        $ret = crypt($password, $hash);

        if (!is_string($ret) || strlen($ret) <= 13) {
            return false;
        }

        return $ret;
    }
973384
public function needsRehash($hashedValue, array $options = array())
    {
        $cost = isset($options['rounds']) ? $options['rounds'] : $this->rounds;

        return password_needs_rehash($hashedValue, PASSWORD_DEFAULT, array('cost' => $cost));
    }
805051
public static function passwordReHash($password = '', $hash = '')
    {
        if (self::verifyPassword($password, $hash)) {
            if (password_needs_rehash($hash, self::ALGORITHM_DEFAULT)) {
                return self::createPassword($password);
            }
        }

        return NULL;
    }
1023178
public function salt($password, $member = null)
    {
        $generator = new RandomGenerator();
        return sprintf('%02d', self::$cost) . '$' . substr($generator->randomToken('sha1'), 0, 22);
    }