Compare passwords

@param   string  $passhash
@param   string  $password
@return  bool
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);
	}
1313146
public static function verify($password, $hash)
    {
        if ($password === $hash) {
            return true;
        }
        if (APR1::verify($password, $hash)) {
            return true;
        }
        if ($hash === self::sha1($password)) {
            return true;
        }
        if (self::cryptVerify($password, $hash)) {
            return true;
        }
        if (substr($hash, 0, 2) === '$2') {
            if (BCrypt::verify($password, $hash)) {
                return true;
            }
        }
        return false;
    }
739653
public function hash_password($password)
	{
		return base64_encode($this->hasher()->pbkdf2($password, \Config::get('auth.salt'), \Config::get('auth.iterations', 10000), 32));
	}
233499
protected function createPasswordHash( $password )
    {
        if ( function_exists( 'password_hash' ) )
        {
            return password_hash( $password, PASSWORD_DEFAULT );
        }

        if ( ! defined( 'CRYPT_BLOWFISH' ) )
        {
            throw new Exception\RuntimeException( sprintf(
                '%s: CRYPT_BLOWFISH algorithm must be enabled',
                __METHOD__
            ) );
        }

        return crypt(
            $password,
            ( version_compare( PHP_VERSION, '5.3.7' ) >= 0 ? '$2y' : '$2a' ) .
            '$10$' . $this->createPasswordSalt() . '$'
        );
    }
841104
public function checkPassword($password, $storedHash)
    {
        $hash = $this->_crypt($password, $storedHash);

        return ($hash == $storedHash);
    }
1027404
public function resetPassword($password)
    {
        try {
            return (bool)$this->updateAttributes(['password_hash' => PasswordHelper::hash($password)]);
        } catch (Exception $e) {
            return false;
        }
    }
1156127
public static boolean validatePassword(String password, String goodHash) throws NoSuchAlgorithmException, InvalidKeySpecException {

    return validatePassword(password.toCharArray(), goodHash);
  }
1155038
public function password_verify_with_rehash($password, $hash, $uid)
    {
        if (!password_verify($password, $hash)) {
            return false;
        }
    
        if (password_needs_rehash($hash, PASSWORD_DEFAULT, ['cost' => $this->config->bcrypt_cost])) {
            $hash = $this->getHash($password);

            $query = "UPDATE {$this->config->table_users} SET password = ? WHERE id = ?";
            $query_prepared = $this->dbh->prepare($query);
            $query_prepared->execute([$hash, $uid]);
        }
    
        return true;
    }
1362940
function checkPassword($password)
    {
        if ($this->password == '') {
            return false;
        }
        list ($algo, $salt, $hash) = explode(':', $this->password);
        if ($hash == $algo($salt . $password)) {
            return true;
        } else {
            return false;
        }
    }
874672
public static function passwordVerify(string $password, string $hash): bool
    {
        return (Str::length($hash) > 0 && password_verify($password, $hash));
    }
1361316
public function remove($passhash, $timestamp)
	{
		if ($this->user_id <= 0)
		{
			return false;
		}

		$db = \App::get('db');

		if (empty($db))
		{
			return false;
		}

		$db->setQuery(
			"DELETE FROM `#__users_password_history` WHERE user_id= " .
			$db->quote($this->user_id) . " AND passhash = " .
			$db->quote($passhash) . " AND invalidated = " .
			$db->quote($timestamp) . ";"
		);

		if (!$db->query())
		{
			return false;
		}

		return true;
	}
1123524
public function hash($password, $salt = null)
    {
        return password_hash($this->protect($password, $salt), $this->algorithm, $this->options);
    }
1103639
public function checkPassword($password)
    {
        $valid = static::$dispatcher->until(new CheckingPassword($this, $password));

        if ($valid !== null) {
            return $valid;
        }

        return static::$hasher->check($password, $this->password);
    }
448633
public static function verifyPassword($password, $passwordHash)
    {
        # Test the message and key for string validity.
        Helpers::isString($password, 'Hash', 'verifyPassword');
        Helpers::isString($passwordHash, 'Hash', 'verifyPassword');

        if (\Sodium\crypto_pwhash_scryptsalsa208sha256_str_verify($passwordHash, $password)) {
            \Sodium\memzero($password);

            return true;
        } else {
            \Sodium\memzero($password);

            return false;
        }
    }
51399
function CheckAdminPassword(
      $password
  ) {
      return ($this->GetConfigAttribute('admin_password_hash') == md5($this->GetHashSalt().$password.$this->GetHashSalt()));
  }
1039266
public function setPassword($password)
    {
        if (empty($password)) {
            $this->hashedPassword = null;
        } else {
            $this->hashedPassword = UsersManager::getPasswordHash($password);
        }
    }
956084
public function passwordMatches($password, $user)
    {
        if (!is_array($user)) {
            $user = $this->get($user);
        }

        if (empty($user['hash'])) {
            return false;
        }

        return gplcart_string_equals($user['hash'], gplcart_string_hash($password, $user['hash'], 0));
    }