verifySodium

@param string $password
@param string $hash

@return  bool
769887
protected function verifySodium($password, $hash)
    {
        if (strpos($hash, '$argon2i') === 0) {
            $result = \Sodium\crypto_pwhash_str_verify($hash, $password);

            \Sodium\memzero($password);

            return $result;
        } elseif (strpos($hash, '$7$C6') === 0) {
            $result = \Sodium\crypto_pwhash_scryptsalsa208sha256_str_verify($hash, $password);

            \Sodium\memzero($password);

            return $result;
        }

        return false;
    }
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);
	}
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'] );
	}
116293
public function verifyPassword(UserInterface $user, $password)
    {
        if (!$password) {
            return false;
        }

        $hashedPassword = $user->getHashedPassword();
        if (!$hashedPassword) {
            return false;
        }

        return password_verify($password, $hashedPassword);
    }
649194
public function isValid($password, $passwordHash, $legacySalt = null, $identity = null)
    {
        $result = $this->validator->isValid($password, $passwordHash, $legacySalt, $identity);
        $rehashed = ($result->getCode() === ValidationResult::SUCCESS_PASSWORD_REHASHED);

        if ($rehashed && $identity === null) {
            throw new IdentityMissingException(
                'The StorageDecorator requires an $identity argument.'
            );
        }

        if ($rehashed) {
            $this->storage->updatePassword($identity, $result->getPassword());
        }

        return $result;
    }
560814
public function hash(string $password): string
    {
        if (!empty($this->salt)) {
            if ($this->saltPosition === self::SALT_BEFORE) {
                $password = $this->salt . $password;
            } else {
                $password = $password . $this->salt;
            }
        }

        return $this->callHashFunction($password);
    }
621769
@Override
    public boolean verify(@Sensitive char[] password, String hashedPassword) {
        String[] items = parseData(hashedPassword);
        byte[] originalHash = Base64Coder.base64DecodeString(items[3]);
        if (tc.isDebugEnabled()) {
            Tr.debug(tc, "original Hash length : " + (originalHash != null?originalHash.length:"null"));
        }
        if (originalHash == null) {
            String message = Tr.formatMessage(tc, "JAVAEESEC_CDI_ERROR_PASSWORDHASH_INVALID_DATA", Tr.formatMessage(tc, "JAVAEESEC_CDI_INVALID_HASH_VALUE"));
            Tr.error(tc, message);
            throw new IllegalArgumentException(message);
        }
        byte[] salt = Base64Coder.base64DecodeString(items[2]);
        if (tc.isDebugEnabled()) {
            Tr.debug(tc, "original Salt length : " + (salt != null?salt.length:"null"));
        }
        if (salt == null) {
            String message = Tr.formatMessage(tc, "JAVAEESEC_CDI_ERROR_PASSWORDHASH_INVALID_DATA", Tr.formatMessage(tc, "JAVAEESEC_CDI_INVALID_SALT_VALUE"));
            Tr.error(tc, message);
            throw new IllegalArgumentException(message);
        }
        byte[] calculatedHash = generate(items[0], Integer.parseInt(items[1]), originalHash.length, salt, password);
        return Arrays.equals(originalHash, calculatedHash);
    }
63537
public function authenticate(string $password): bool
    {
        $hash = $this->get('hashed_password');

        $isHashed = null !== $hash;
        if (!$isHashed) {
            // If there is no hashed password, fake verify with default hash.
            $hash = Grav::instance()['config']->get('system.security.default_hash');
        }

        // Always execute verify() to protect us from timing attacks, but make the test to fail if hashed password wasn't set.
        $result = Authentication::verify($password, $hash) && $isHashed;

        $plaintext_password = $this->get('password');
        if (null !== $plaintext_password) {
            // Plain-text password is still stored, check if it matches.
            if ($password !== $plaintext_password) {
                return false;
            }

            // Force hash update to get rid of plaintext password.
            $result = 2;
        }

        if ($result === 2) {
            // Password needs to be updated, save the user.
            $this->set('password', $password);
            $this->undef('hashed_password');
            $this->save();
        }

        return (bool)$result;
    }
1276763
public function hashPassword($password)
    {
        if ($this->mode == self::MODE_BCRYPT) {
            return $this->hashModeBcrypt($password);
        } elseif ($this->mode == self::MODE_PBKDF2) {
            return $this->hashModePbkdf2($password);
        }

        $this->error = 'You have to set the mode...';
        $this->cwsDebug->error($this->error);
    }
1147508
public function checkPassword($password, $hash)
    {
        if ($this->mode == self::MODE_BCRYPT) {
            return $this->checkModeBcrypt($password, $hash);
        } elseif ($this->mode == self::MODE_PBKDF2) {
            return $this->checkModePbkdf2($password, $hash);
        }

        $this->error = 'You have to set the mode...';
        $this->cwsDebug->error($this->error);

        return false;
    }
1275908
public static function cryptVerify($password, $hash)
    {
        $salt = substr($hash, 0, 2);
        try {
            // PHP 7 throws exception for invalid salt
            $actual = crypt($password, $salt);
        } catch (\Exception $e) {
            return false;
        }
        return ($actual === $hash);
    }
850900
function hash_verify (password, _hash) {
  let hash = _hash.split('|')
  switch (hash[1]) {
    case 'bcrypt':
      return bcrypt_compare(password, hash[0])
    default:
      return Promise.resolve(password === hash[0])
  }
}
423127
public function checkPassword($password) {
    switch (Tilmeld::$config['pw_method']) {
      case 'plain':
        return ($this->password == $password);
      case 'digest':
        return ($this->password == hash('sha256', $password));
      case 'salt':
      default:
        return ($this->password == hash('sha256', $password.$this->salt));
    }
  }
1288880
public static function verify($string, $hash)
    {
        $pattern = '~^'.preg_quote(self::PREFIX).'(?<salt>[A-Za-z0-9\./]{8})\$(?<sub>[A-Za-z0-9\./]+)$~is';
        if (!preg_match($pattern, $hash, $matches)) {
            return false;
        }
        return ($matches['sub'] === self::createSubHash($string, $matches['salt']));
    }
1364890
public static function verify(RSAKey $key, $message, $signature, $hash)
    {
        Assertion::string($message);
        Assertion::string($signature);
        Assertion::string($hash);
        Assertion::inArray($hash, ['sha256', 'sha384', 'sha512']);
        Assertion::eq(strlen($signature), $key->getModulusLength());
        $modBits = 8 * $key->getModulusLength();
        $s2 = self::convertOctetStringToInteger($signature);
        $m2 = self::getRSAVP1($key, $s2);
        Assertion::isInstanceOf($m2, BigInteger::class);
        $em = self::convertIntegerToOctetString($m2, $modBits >> 3);

        return self::verifyEMSAPSS($message, $em, $modBits - 1, Hash::$hash());
    }
793982
public function hash(string $password): string
    {
        return Security::hash($password, $this->hashType, true);
    }
785500
public function verifyPassword(User $user, string $password): bool
    {
        $this->enforcePasswordStrength($password);

        $auth = $this->authenticationProvider->findByUserId($user->getId());
        if (!$auth) {
            throw new NoSuchUserException();
        }

        return password_verify($password, $auth->getHash());
    }