Passwordless

Passkeys and WebAuthn Explained: Phishing-Resistant Login

What passkeys actually are, how WebAuthn works under the hood, why they resist phishing where passwords and OTPs fail, and how to adopt them without locking users out.

Emilian GheoneaJune 6, 20267 min read

Passwords leak. One-time codes get phished through fake login pages and SIM swaps. Passkeys are the industry's answer — a login method that is both easier for users and fundamentally resistant to phishing. This article explains what passkeys are, how the underlying WebAuthn standard works, exactly what your server has to store and verify, and what to think about before rolling them out.

What is a passkey?

A passkey is a public/private key pair bound to a specific website, created and stored by the user's device. There's no shared secret to leak: the private key never leaves the device, and the server only ever stores the public key. To log in, the device proves it holds the private key by signing a challenge.

Passkeys are built on two web standards: WebAuthn (the browser API) and CTAP (the protocol between the browser and authenticators like phones, laptops, and security keys). Together they're often called FIDO2.

The user experience is what makes them compelling: instead of typing a password, the user approves the login with the same biometric or PIN they already use to unlock their device — Face ID, a fingerprint, or a screen lock. There is nothing to remember, nothing to type, and — crucially — nothing to hand to an attacker.

Why passkeys resist phishing

This is the part that matters most. A passkey is cryptographically bound to the website's origin (its domain). When you register a passkey for example.com, the browser records that origin. If a user later lands on examp1e.com — a convincing phishing clone — the browser simply will not offer the passkey, because the origin doesn't match.

Compare that to passwords and OTPs: a user can be tricked into typing either into a fake page, and an attacker relays them to the real site in real time. This is exactly the attack that defeats even TOTP and SMS codes — the OTP is a secret the user can be socially engineered into revealing. Passkeys remove the human from the trust decision entirely. There is no secret the user can be persuaded to hand over, because the "secret" is a private key the user never sees and the browser will only use on the correct origin.

This origin binding is why passkeys sit at the top of any serious ranking of authentication methods against the phishing and account-takeover failure modes covered in Common Authentication Vulnerabilities.

How WebAuthn works, step by step

WebAuthn has two ceremonies: registration (creating a passkey) and authentication (using it).

Rendering diagram…

Registration

  1. The server generates a random challenge and sends it to the browser along with the site's identifier (the "relying party ID") and the user's info.
  2. The browser calls navigator.credentials.create(). The authenticator generates a new key pair scoped to this origin and prompts the user (biometric/PIN).
  3. The authenticator returns the public key and a signed attestation proving the credential was created.
  4. The server verifies the response and stores the public key and a credential ID against the user's account.

Authentication

  1. The server sends a fresh random challenge.
  2. The browser calls navigator.credentials.get(). The user approves with their biometric/PIN.
  3. The authenticator signs the challenge with the private key.
  4. The server verifies the signature using the stored public key. If it checks out, the user is authenticated.

The challenge is single-use and random, which defeats replay attacks. The signature proves possession of the private key without ever revealing it.

What your server actually stores

A frequent point of confusion is what lives in your database. For each registered passkey you persist a small record — never anything secret:

FieldPurpose
credentialIdOpaque handle the authenticator returns; used to look up the key at login
publicKeyThe public half of the key pair; verifies signatures
signCountA counter the authenticator increments; helps detect cloned credentials
transportsHints (internal, usb, hybrid) so the browser suggests the right authenticator
userIdThe account this passkey belongs to

Because none of these are secrets, a database breach does not hand attackers a way to log in — a categorical improvement over stored password hashes, which are still crackable offline.

Verifying a passkey on the server

You should never hand-roll WebAuthn crypto; use a maintained library (@simplewebauthn/server for Node, webauthn for Python, go-webauthn for Go). The shape is always the same — generate options with a challenge, then verify the authenticator's response against the stored public key:

import {
  generateAuthenticationOptions,
  verifyAuthenticationResponse,
} from '@simplewebauthn/server';

// 1. Login begins — issue a challenge and remember it server-side
const options = await generateAuthenticationOptions({ rpID: 'example.com' });
await saveChallenge(session, options.challenge);

// 2. Browser returns the signed assertion — verify it
const verification = await verifyAuthenticationResponse({
  response: assertionFromBrowser,
  expectedChallenge: await loadChallenge(session),
  expectedOrigin: 'https://example.com',
  expectedRPID: 'example.com',
  credential: {
    id: stored.credentialId,
    publicKey: stored.publicKey,
    counter: stored.signCount,
  },
});

if (verification.verified) {
  await updateSignCount(stored.credentialId, verification.authenticationInfo.newCounter);
  // Establish your own session from here
}

Note the last comment: authenticating the passkey proves who the user is; what you do next — issuing a session cookie or token — is your application's job. The trade-offs there are covered in Session Management Best Practices.

Synced vs. device-bound passkeys

There are two flavors, and the distinction affects your recovery strategy:

  • Synced passkeys are backed up to a cloud keychain (iCloud Keychain, Google Password Manager, etc.) and follow the user across their devices. Great for usability — if they get a new phone, their passkeys come with them.
  • Device-bound passkeys never leave the hardware they were created on (typical of physical security keys like YubiKeys). Stronger guarantees, but losing the device means losing that credential.

Most consumer products lean on synced passkeys for reach; high-assurance environments may require device-bound keys. If you need to enforce device-bound hardware, that's what attestation is for — the signed statement from the authenticator during registration that tells you the make and security properties of the device. Most consumer apps ignore attestation entirely (requesting it adds friction and privacy concerns); regulated environments use it to allow only approved authenticator models.

Discoverable credentials and conditional UI

Two features turn passkeys from "a setting power users find" into "the default everyone uses":

  • Discoverable credentials (resident keys) let the authenticator remember which account a passkey belongs to, so the user doesn't even type a username first.
  • Conditional UI ("autofill") surfaces the passkey right in the username field. Adoption climbs sharply when it's this frictionless:
if (window.PublicKeyCredential?.isConditionalMediationAvailable) {
  const available = await PublicKeyCredential.isConditionalMediationAvailable();
  if (available) {
    navigator.credentials.get({ publicKey: options, mediation: 'conditional' });
  }
}

Pair that with an autocomplete="username webauthn" attribute on your input and returning users see a one-tap login suggestion.

Adoption without lockouts

The biggest risk in rolling out passkeys isn't security — it's accidentally locking users out. Practical guidance:

  • Treat passkeys as additive at first. Let users add a passkey alongside their existing password or email login rather than forcing a switch.
  • Allow multiple passkeys per account so a user can register their phone and their laptop and a backup security key.
  • Keep a recovery path. Email-based magic links or recovery codes give users a way back in if they lose access to their authenticators.
  • Use conditional UI so returning users see a passkey suggestion right in the username field.
  • Show users their registered passkeys in account settings, with device names and the ability to revoke.

Common mistakes

  • Reusing or not checking the challenge. The challenge must be random, single-use, and validated server-side. Skipping this reopens replay attacks.
  • Trusting the client's origin claim. Always compare expectedOrigin and expectedRPID on the server; never take the browser's word for it.
  • Ignoring signCount regressions. A counter that goes backwards can indicate a cloned credential — at minimum, log it.
  • Forcing passkey-only with no fallback. A single lost device becomes a support ticket, or a lost customer.

Passkeys vs. passwords vs. OTP

PropertyPasswordTOTP / SMS OTPPasskey
Phishing-resistantNoNoYes
Shared secret on serverHash (crackable)Seed / nonePublic key only
Replayable if interceptedYesYes (within window)No
User frictionType + rememberType a codeOne biometric tap
Recovery complexityLowMediumMedium–High

Where passkeys fit alongside other methods

Passkeys don't have to be all-or-nothing. A pragmatic modern auth stack often looks like:

  • Passkeys as the primary, phishing-resistant method.
  • Magic links or OTP as a fallback and for account recovery.
  • Passwords retained only for users who haven't migrated yet, with a nudge to upgrade.

The direction of travel is clear: passwords are slowly being demoted from "the way you log in" to "the legacy fallback." Passkeys won't replace every method overnight, but for most products they're now the best default to offer — better security and a better experience at the same time, which is a rare combination in authentication.

Building auth into a SaaS product and weighing which methods to expose? EmbedAuth's embeddable sign-in covers passwords, magic links and email one-time codes today. It does not support passkeys yet, so if WebAuthn is a requirement, the ceremonies above are the part to plan for.

Written by

Emilian Gheonea

Senior Blockchain & Full-Stack Software Engineer. I build EmbedAuth — an embeddable authentication platform for SaaS — and write about the auth problems most teams hit too late.