logo svg
logo

October 24, 2025

Updated: November 3, 2026

How Do Passkeys Work for Passwordless Auth

Learn how passkeys use public key cryptography and WebAuthn to replace passwords. See registration, login flow, risks, code, and best practices for rollout.

Khaled Hassan

Khaled Hassan

Featured Image

Introduction

Passwords fail often. Users forget them. Attackers phish them. Breached databases leak them. The result is lockouts, fraud, and high support cost. Passkeys promise a better path. They remove shared secrets from servers and replace them with public key cryptography held by the user’s authenticator. The login becomes a quick local check, a fingerprint or face scan or PIN, then a signed challenge to the site. No typing. No SMS codes. No phishable links.

In this guide, you will learn how passkeys work end to end. We start with plain definitions, then walk the full flow for registration and sign in. You will see the moving parts, authenticators, relying parties, key pairs, and what each one does. We compare validation and verification since teams often confuse those steps. We cover risks and pitfalls, such as RP ID mismatches and device loss, with fixes that you can ship today. We include code that you can drop into a small demo. Finally, we share best practices that map to real production, rate limits, timeouts, error paths, and privacy notices. If you want a clear answer to “how do passkeys work,” plus a path to deploy, this article is for you.

Sources for claims and figures are cited inline. For example, WebAuthn Level 3 defines the API and scoping rules, and platform vendors document passkey security and recent updates.

What Is a Passkey?

Passkeys are FIDO based credentials that replace passwords. A site stores a public key. The user's authenticator stores the private key, either on one device or security key (device-bound) or in a credential manager that syncs it across the user's devices (synced), and protects it with a local unlock method, such as biometrics or a PIN. Sign in is a signed challenge, not a shared secret. This passwordless approach builds on FIDO Authentication, an open standard that uses cryptographic key pairs to verify users without relying on shared passwords.

Passwordless doesn't mean flawless — our web app penetration testing services check the implementation before you rely on it.

How it works, step by step

We will use the WebAuthn terms: relying party (your site), authenticator (the device or security key), and user.

Registration

  1. The site creates a random challenge and sends a navigator.credentials.create() request with parameters such as RP ID, user handle, and acceptable algorithms. W3C
  2. The device prompts the user to unlock.
  3. The authenticator generates a key pair scoped to the RP ID. The private key stays with the authenticator: on a security key or other device-bound passkey it never leaves the hardware, while a synced passkey is copied to the user's other devices through the platform's end-to-end encrypted credential manager. The public key and an attestation object return to the site. W3C
  4. The site validates the response and stores the public key with the user’s account.

Authentication

  1. The site creates a new challenge and calls navigator.credentials.get() with the RP ID and allow list.
  2. The user unlocks the device.
  3. The authenticator signs the challenge and origin data with the stored private key.
  4. The site verifies the signature using the stored public key and checks the origin, RP ID, challenge, and counter.

Reference, WebAuthn Level 3 formalizes creation and use of public key credentials, scoped to the RP and origin. W3C

[User] unlocks device
   ↓ local biometrics or PIN
[Authenticator] creates key pair or signs challenge
   ↓
[Browser WebAuthn] packages response
   ↓ HTTPS
[Relying Party] validates or verifies and updates session

Anatomy of a passkey

Breakdown of the core objects you will see in code and logs.

Example server record (illustrative)

json
{
  "userHandle": "01F4C2...",
  "rpId": "example.com",
  "credentials": [
    {
      "credId": "A1b2C3...",
      "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkq...\n-----END PUBLIC KEY-----",
      "signCount": 12,
      "addedAt": "2025-10-24T12:00:00Z",
      "attestation": "none"
    }
  ]
}

Validation vs verification

Teams mix these terms. Keep them separate.

When to use which

AspectValidation, registrationVerification, authentication
GoalTrust the new credentialTrust the current login
InputsAttestation, public key, challenge, originChallenge, origin, authenticator data, signature
OutputStore credential, link to userIssue session or token
Typical failureRP ID mismatch, bad attestationReplay, wrong origin, bad signature

Specification, WebAuthn defines both the creation ceremony and assertion ceremony, with conformance requirements for RP ID scope and origin checks.

Common pitfalls and security risks

Note: keep WebAuthn payloads out of headers

Do not stuff binary WebAuthn responses into headers. They can be large, especially with attestation, and may exceed header limits on some CDNs and WAFs. Use JSON bodies over HTTPS. Keep challenge payloads small. This avoids 413 or 431 errors.

Implementation guide

Below is a simplified flow to illustrate the checks. It uses WebAuthn with a typical Node backend and the @simplewebauthn/server library (API as of v14). It is not production-ready: it keeps users and challenges in memory, so use a session store and follow the library's current documentation.

passkeys-demo/
├── server/
│   ├── index.js
│   └── verify.js
├── web/
│   ├── register.js
│   └── signin.js
└── README.md

1) Server, create registration options

// server/index.js
import express from "express";
import crypto from "crypto";

const app = express();
app.use(express.json());

const rpId = "example.com";
const users = new Map(); // userHandle -> { credentials: [] }
const challenges = new Map(); // userHandle -> expected challenge (use a server-side session store in production)

app.post("/register/options", (req, res) => {
  const { userHandle, username } = req.body;
  const challenge = crypto.randomBytes(32).toString("base64url");
  challenges.set(userHandle, challenge); // kept server-side and checked on verify
  res.json({
    rp: { id: rpId, name: "Example Inc." },
    user: {
      id: Buffer.from(userHandle, "hex"),
      name: username,
      displayName: username
    },
    challenge,
    pubKeyCredParams: [{ type: "public-key", alg: -7 }, { type: "public-key", alg: -257 }],
    attestation: "none",
    timeout: 300000 // W3C recommended default, 5 minutes
  });
});

2) Client, call navigator.credentials.create

// web/register.js
async function register(userHandle, username) {
  const opts = await fetch("/register/options", {
    method: "POST",
    headers: { "content-type": "application/json" },
    body: JSON.stringify({ userHandle, username })
  }).then(r => r.json());

  opts.challenge = Uint8Array.from(atob(opts.challenge.replace(/-/g, "+").replace(/_/g, "/")), c => c.charCodeAt(0));
  opts.user.id = Uint8Array.from(opts.user.id.data || opts.user.id); // handle Buffer serialization

  const cred = await navigator.credentials.create({ publicKey: opts });
  // Send the credential as JSON with base64url fields, the shape the server library expects
  await fetch("/register/verify", {
    method: "POST",
    headers: { "content-type": "application/json" },
    body: JSON.stringify({ userHandle, credential: cred.toJSON() })
  });
}

3) Server, validate and store public key

Use a well tested library in production. The example below shows the checks that must pass, challenge, origin, RP ID, and user verification. The challenge is stored server-side when options are created and passed back as expectedChallenge.

// server/verify.js
import { verifyRegistrationResponse } from "@simplewebauthn/server"; // API as of v14

app.post("/register/verify", async (req, res) => {
  const { userHandle, credential } = req.body;
  const expectedChallenge = challenges.get(userHandle);
  challenges.delete(userHandle); // one-time use
  if (!expectedChallenge) return res.status(400).json({ ok: false });

  let verification;
  try {
    verification = await verifyRegistrationResponse({
      response: credential,
      expectedChallenge,
      expectedOrigin: "https://example.com",
      expectedRPID: rpId,
      requireUserVerification: true
    });
  } catch (err) {
    return res.status(400).json({ ok: false });
  }

  if (!verification.verified) return res.status(400).json({ ok: false });

  const { id, publicKey, counter } = verification.registrationInfo.credential;
  const record = users.get(userHandle) || { credentials: [] };
  record.credentials.push({ credId: id, publicKey, signCount: counter });
  users.set(userHandle, record);
  res.json({ ok: true });
});

4) Authentication options and navigator.credentials.get

// server/index.js
app.post("/auth/options", (req, res) => {
  const { userHandle } = req.body;
  const user = users.get(userHandle);
  if (!user) return res.status(404).end();
  const challenge = crypto.randomBytes(32).toString("base64url");
  challenges.set(userHandle, challenge); // kept server-side and checked on verify
  const allowCredentials = user.credentials.map(c => ({
    type: "public-key",
    id: Buffer.from(c.credId, "base64url")
  }));
  res.json({ challenge, rpId, allowCredentials, userVerification: "required", timeout: 300000 });
});
// web/signin.js
async function signIn(userHandle) {
  let opts = await fetch("/auth/options", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ userHandle }) }).then(r => r.json());
  opts.challenge = Uint8Array.from(atob(opts.challenge.replace(/-/g, "+").replace(/_/g, "/")), c => c.charCodeAt(0));
  opts.allowCredentials = opts.allowCredentials.map(c => ({ ...c, id: Uint8Array.from(c.id.data || c.id) }));
  const assertion = await navigator.credentials.get({ publicKey: opts });
  // Send the assertion as JSON with base64url fields
  await fetch("/auth/verify", {
    method: "POST",
    headers: { "content-type": "application/json" },
    body: JSON.stringify({ userHandle, credential: assertion.toJSON() })
  });
}
// server/verify.js
import { verifyAuthenticationResponse } from "@simplewebauthn/server";

app.post("/auth/verify", async (req, res) => {
  const { userHandle, credential } = req.body;
  const expectedChallenge = challenges.get(userHandle);
  challenges.delete(userHandle); // one-time use
  const user = users.get(userHandle);
  const cred = user && user.credentials.find(c => c.credId === credential.id);
  if (!expectedChallenge || !cred) return res.status(401).json({ ok: false });

  let verification;
  try {
    verification = await verifyAuthenticationResponse({
      response: credential,
      expectedChallenge,
      expectedOrigin: "https://example.com",
      expectedRPID: rpId,
      credential: { id: cred.credId, publicKey: cred.publicKey, counter: cred.signCount },
      requireUserVerification: true
    });
  } catch (err) {
    return res.status(401).json({ ok: false });
  }

  if (!verification.verified) return res.status(401).json({ ok: false });
  cred.signCount = verification.authenticationInfo.newCounter;
  res.json({ ok: true, session: "new-session-id" });
});

Platform notes

Performance and limits

Best practices checklist

Use cases and anti-patterns

Fits well

Avoid or use alternatives

Alternatives

For deeper help, see DeepStrike’s penetration testing services to pressure test authentication and recovery paths, and to model phishing resistance in the real world.

Conclusion

Passkeys remove passwords and their failures, phishing, reuse, and weak secrets. They shift trust to strong cryptography that is bound to your site and to the user’s authenticator or credential manager. The login becomes a short local unlock and a signed challenge. Teams get higher success rates, faster sign ins, and a simpler stack. The rollout does need care, RP ID scope, recovery planning, and clear UX. Start with a hybrid phase, measure success, and expand to admin consoles first. Modern platforms document policy and deployment steps, and the WebAuthn Level 3 spec shows exactly what to validate and verify. If you need help pressure testing your rollout, consider a focused engagement to simulate attacks and recovery edge cases. Learn more at DeepStrike’s penetration testing services, then build a plan and ship.

Common FAQs

Are passkeys the same as FIDO2 or WebAuthn?
Passkeys are user friendly packaging of FIDO2 WebAuthn credentials. Same crypto, better UX. FIDO Alliance

Do I still need passwords?
You can keep them as a fallback. The goal is to phase them out as device support grows. Many platforms allow both during transition. The LastPass Blog

What about cross device use?
Platform managers sync passkeys with end to end encryption. Apple and Google shipped improvements in 2025 to make this smoother. Apple Developer

Are passkeys phishing resistant?
Yes. Credentials are bound to the origin. A fake site cannot produce a valid signature that matches your RP ID and origin checks. Accounts stay phishable through any password, SMS or email fallback you leave enabled, so restrict or remove those paths once users have passkeys. W3C

How fast are passkeys in practice?
Public data shows higher success and faster sign ins at large scale, including Google reporting 30 percent higher success and 20 percent faster sign ins. FIDO Alliance

Do they work on Windows, macOS, iOS, and Android?
Yes, all major vendors support passkeys and document setup and policy

background
Let's hack you before real hackers do

Stay secure with DeepStrike penetration testing services. Reach out for a quote or customized technical proposal today

Contact Us