Notes

PHP Passkeys: How I Verify WebAuthn in Plain PHP

PHP passkeys without Composer: how I verify WebAuthn for WordPress in plain PHP, the five checks to run in order, and when to use a library instead.

4 min read Updated Oct 26, 2026 Passkeys PHP WordPress

Verifying passkeys in plain PHP: five checks in order, challenge, client data, authenticator data, signature and sign count, ending at signed in

When I added passwordless sign-in to Passkey First, I could have pulled in a PHP WebAuthn library through Composer. I wrote the verifier myself in plain PHP instead. Below is what “PHP passkeys” involve on the server side, what my verifier checks, and when I’d use a library.

If you only want passkey login on your WordPress site and don’t care how it works, skip to my ten-minute setup guide.

What a passkey sign-in is, from the server’s side

A passkey is a WebAuthn credential. The private key stays on the person’s phone, laptop or password manager. Your server only stores the public key. Every sign-in takes two round trips:

  1. The server creates a random challenge and sends it to the browser.
  2. The browser calls navigator.credentials.get(). The device asks for a fingerprint, face or PIN, then signs the challenge with the private key.
  3. The browser posts back three pieces: clientDataJSON, authenticatorData and the signature.
  4. The server checks those pieces against the stored public key and decides yes or no.
A passkey sign-in in four steps between the PHP server and the browser

Step 4 is the whole job of a PHP passkey library, and most of it is careful byte handling.

Why I skipped Composer

There are good PHP WebAuthn libraries. lbuchs/WebAuthn is small and readable and supports every common attestation format. web-auth/webauthn-lib is the full framework, actively maintained, and needs PHP 8.2 or newer plus a long list of Symfony and CBOR packages.

In a WordPress plugin, both run into the same problem. WordPress has no shared Composer setup, so two plugins that bundle different versions of the same library can break each other. I also wanted Passkey First to run on PHP 7.4, which a lot of shared hosts still use. So I kept the scope narrow: about 1,300 lines of plain PHP in total, with no build step.

What my verifier checks

The checks run in this order in the plugin’s code. If any one of them fails, the sign-in fails, with no “probably fine” fallback.

The five checks the PHP passkey verifier runs, in order, ending at signed in

1. The challenge is real and single use

The challenge is 32 random bytes from random_bytes(), stored for two minutes. When the response comes back, the challenge is read and deleted in one step, and only the request whose delete succeeds gets to use it, so two requests racing each other can’t both spend it. The challenge is also bound to the browser that started the sign-in.

2. clientDataJSON says the right thing

The browser’s client data is plain JSON. My verifier checks that type is webauthn.get, that the challenge matches with hash_equals() (constant time, never ==), and that the origin is exactly the site’s own https:// address. It also refuses cross-origin use, because a passkey for my login page has no business being used inside someone else’s frame.

3. authenticatorData is bound to this site

The first 32 bytes of the authenticator data are a SHA-256 hash of the relying party ID, which is the site’s host name. The verifier hashes the host name itself and compares the two. Then it reads the flags byte: user presence must be set, and user verification (the fingerprint, face or PIN step) is required. That last flag is why a passkey counts as two factors on its own.

4. The signature verifies

The signed message is the raw authenticator data followed by the SHA-256 of the client data JSON. PHP’s openssl_verify() checks it against the stored public key with SHA-256. It supports ES256 (elliptic curve) and RS256 (RSA, 2048 bits or more), which covers the passkeys built into current iPhones, Android phones, Macs and Windows machines.

Early on I expected the signature format to be a problem. WebAuthn ES256 signatures arrive DER-encoded, which is what OpenSSL expects, so there’s nothing to convert. The public key took more work. At enrolment it arrives as a COSE key inside CBOR, and I convert it to a PEM once and store that.

5. The sign count moves forward

Authenticators can report a counter. Once either the stored or the new value is above zero, the new one must be strictly higher, or the verifier rejects it as a possible cloned credential. Synced passkeys usually report zero every time, which is allowed.

What I deliberately left out

My verifier uses attestation format “none” at enrolment. It keeps the public key and doesn’t try to prove which brand of device made it. For a site login, what matters is that the same key comes back each time, so I think that’s the right call. If you need to restrict sign-in to approved hardware keys, for example in a regulated office, use a full library that verifies attestation certificates.

The CBOR decoder is minimal and refuses trailing bytes and deep nesting. I kept it that tight on purpose, since a parser that fails closed is easier to trust than a broad one.

How I tested it

A software passkey that produces real ES256 and RS256 signatures drives 35 verifier tests, plus 26 end-to-end tests against WordPress with the Two Factor plugin installed. GitHub Actions runs them on PHP 7.4 through 8.5.

As the plugin page says, the passwordless layer follows the WebAuthn specification and fails closed, but it hasn’t had an independent security audit yet. It ships switched off. I recommend Optional mode, which adds the passkey button and keeps passwords working. Enrol at least two passkeys before you require them.

Library or hand-rolled: my rule of thumb

  • Building a standalone PHP app with Composer already in place? Use a library. lbuchs/WebAuthn if you want something small, web-auth if you want the whole framework.
  • Shipping a WordPress plugin to unknown hosts? Keep dependencies at zero if you can, keep the scope narrow and test with real signatures.
  • Just want passkeys on your own WordPress admin? Don’t write anything. Install Passkey First, which sits on top of the core team’s Two Factor plugin and its WebAuthn provider, and follow the setup guide.

If you also want your WordPress mail off SMTP passwords, I wrote a guide to sending WordPress email through Microsoft 365 for the same reason. Everything I give away is listed on the Tools page.