Search by

whatbox / recaptcha-password-check

anthonyryan1

PHP client for Google's reCAPTCHA password check API

Package info

github.com/whatbox/recaptcha-password-check

pkg:composer/whatbox/recaptcha-password-check

Statistics

Installs: 802

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

1.0.2 2026-09-06 22:38 UTC

This package is auto-updated.

Last update: 2026-09-06 23:01:42 UTC


README

PHP port of Google's Java API client for the reCAPTCHA Enterprise Password Check API.

A privacy-respecting solution to check username, password pairs against known breaches without leaking customer usernames or passwords to the breach database.

Similar to Have I Been Pwned, but a commercial API with fewer false positives by considering username and password together, instead of password alone.

Requirements

  • PHP 8.1+
  • ext-scrypt is optional, but recommended for performance

Installation

composer require whatbox/recaptcha-password-check

Usage

<?php

use ReCaptcha\PasswordCheck\Client\ReCaptchaPasswordCheckClient;

$client = new ReCaptchaPasswordCheckClient($projectId, $apiKey);
$result = $client->checkPassword(
    $username,
    $password,

    // Optional: If you use reCAPTCHA bot protection, you can attach this password check to the
    // reCaptcha Token and feed Google additional data in exchange for more accurate bot scores
    // expectedAction: 'login',
    // eventOverrides: [
    //     'siteKey' => $siteKey,
    //     'token' => $recaptchaToken,
    // ]
);

if ($result->areCredentialsLeaked()) {
    // Prompt the user to reset their password.
}

Granular Usage

<?php

use ReCaptcha\PasswordCheck\Client\ReCaptchaPasswordCheckClient;
use ReCaptcha\PasswordCheck\PasswordCheckVerification;

$client = new ReCaptchaPasswordCheckClient($projectId, $apiKey);

// Hashing and crypto (CPU bound)
$verification = PasswordCheckVerification::create($usernameOrEmail, $password);

// Sending to Google (Network latency bound)
$result = $client->completeVerification($verification);

if ($result->areCredentialsLeaked()) {
    // Prompt the user to reset their password.
}

The $verification object holds the private key needed to decrypt Google's response, so it must be the same instance for both phases and must never be serialized to shared storage.

Running tests

composer test

Project structure

  • src/Crypto – Elliptic-curve primitive, hash type enum, and supported curves.
  • src/Utils – Username canonicalization, PHP Scrypt, and bit-prefix helpers.
  • src/Client – High-level HTTP client for Google reCAPTCHA Password Check.
  • tests/ – PHPUnit test suite mirroring the upstream reference coverage.

License

Apache 2.0 – consistent with the upstream Google reference implementations.