What Is a Credential in Keycloak?
A complete, zero-jargon walkthrough of how Keycloak stores and checks the proof behind every login — passwords, one-time codes, hardware keys, and everything in between — without ever exposing the secret itself.
Think about how a bank verifies you at the counter. Sometimes it’s your signature. Sometimes it’s a PIN. Sometimes it’s your passport. Each of these is a different kind of proof, but they all answer the same question: “can you show me something that proves you are who you claim to be?” In Keycloak, every one of these different kinds of proof — a password, a fingerprint scan, a one-time code from a phone app, a physical security key — is represented by the same underlying concept: a Credential. By the end of this guide, you’ll understand exactly what a Credential is, how Keycloak stores it safely, and how it gets checked every time someone tries to log in.
ACore Concepts
Before touching architecture, let’s build the vocabulary — starting with what a Credential actually represents inside Keycloak.
A Credential in Keycloak is a stored piece of evidence attached to a user’s account that Keycloak uses to verify their identity during login. The most familiar example is a password, but Keycloak treats many other proof types the same way: a one-time code generator (OTP), a WebAuthn hardware security key, a recovery code, or even a client certificate. Each of these is stored as its own Credential record, and a single user account can hold several different Credentials at once, giving them multiple ways to prove who they are.
It helps to separate two ideas that are easy to blur together. Authentication is the overall process of proving identity — the login flow as a whole. A Credential is the specific artifact used as evidence during that process. You can think of authentication as the exam, and a Credential as one specific answer sheet a user is allowed to submit as proof they studied.
Picture a hotel safe in your room. To open it, you might set a numeric code, or the hotel might issue you a keycard instead, or some safes accept a fingerprint. Whichever method you use, the safe doesn’t store your fingerprint image or your typed code in a way a thief could simply read and reuse elsewhere — it stores a transformed version that only proves a match at the moment you use it. A Keycloak Credential works the same way: it’s not a copy of your secret sitting in plain view, it’s a securely stored proof-checker for that specific secret.
A few terms recur constantly in any Credential conversation, and getting them straight now makes the rest of this guide far easier to follow:
Credential
A stored proof record tied to one user account — a password, an OTP generator registration, a security key registration, and so on. Multiple Credentials can exist per user.
Credential Type
The kind of proof a Credential represents — “password,” “otp,” “webauthn,” or “recovery-codes” are common built-in types Keycloak supports out of the box.
Hashing
A one-way mathematical transformation applied to a password before storage, so the original text is never kept anywhere — Keycloak only ever stores the transformed version.
Salt
A random value mixed into the hashing process for each password individually, ensuring that even two users with the identical password end up with completely different stored values.
Multi-Factor Authentication (MFA)
Requiring more than one Credential type during login — typically a password plus an OTP or security key — so a single stolen secret isn’t enough on its own.
Authentication Flow
The configurable sequence of steps Keycloak walks through during login, deciding which Credential types are required, optional, or alternative for a given user.
It’s worth being precise about one common confusion: a Credential is not the same thing as a Role or a Group. Roles and Groups describe what a user is allowed to do once they’re recognized. A Credential is purely about the earlier step — proving who they are in the first place. Authentication happens first, using Credentials; authorization happens after, using Roles and Groups.
A Credential answers “can you prove this is really you?” A Role or Group answers “now that we know it’s you, what are you permitted to do?” — two separate questions, handled by two separate parts of Keycloak.
BArchitecture & Components
Credentials don’t exist in isolation — they sit inside a small ecosystem of cooperating Keycloak components. Let’s map that ecosystem out.
Every Credential belongs to exactly one User, inside exactly one Realm — Keycloak’s isolation boundary. Around that simple relationship sit several components responsible for storing, protecting, and checking Credentials safely.
graph TD
U["User Account"] -->|"owns one or more"| CR["Credentials
(password, OTP, WebAuthn...)"]
CR -->|"protected by"| HASH["Hashing Algorithm
+ Per-Credential Salt"]
R["Realm
(isolation boundary)"] --> U
R -->|"defines rules via"| FLOW["Authentication Flow"]
FLOW -->|"decides which
Credential types apply"| CR
U -->|"login attempt"| FLOW
FLOW -->|"verifies match,
never reads secret"| CR
FLOW -->|"on success"| TOKEN["Signed Token Issued"]
Fig 1 — How Credentials fit among Keycloak’s core building blocks
Each labeled component in that diagram has a distinct job:
User Account
The person the Credential belongs to. One User can hold several different Credentials — for example, a password plus a registered OTP device.
Credential Record
The stored proof itself — never the raw secret, but a protected representation Keycloak can check a submitted value against.
Hashing Algorithm + Salt
The mathematical machinery that transforms a submitted password into something comparable to the stored record, without either value ever being reversible back to plain text.
Realm
The isolated space Credentials live inside — a Credential registered in one Realm is invisible to, and cannot be reused in, a different Realm.
Authentication Flow
A configurable sequence describing exactly which Credential types are required, optional, or offered as alternatives during login for that Realm.
Signed Token
What the user receives after every required Credential check succeeds — proof of a completed login that other applications can trust without re-checking any secret themselves.
Picture a building’s front desk with a rulebook taped to the counter: “Visitors must show a photo ID. Contractors must additionally show a work order.” The rulebook is the Authentication Flow — it decides which forms of proof (Credentials) are required for which kind of visitor. The security guard never keeps a photocopy of your ID in a drawer for later; they simply confirm it matches, on the spot, every time — exactly how Keycloak checks a Credential without ever storing or exposing the original secret.
An important architectural nuance: because an Authentication Flow is configurable per Realm, two Realms in the same Keycloak deployment can enforce completely different Credential requirements — one Realm might require only a password, while another requires a password plus a hardware security key, even though both are running on the same underlying Keycloak installation.
CHow Credentials Work Internally
Now let’s open the hood and see exactly how a typed password becomes a verified login, without the original secret ever being stored anywhere in readable form.
When a user sets a password, Keycloak never stores the password itself. Instead, it runs the password through a one-way hashing algorithm — a mathematical function that turns readable text into a scrambled value that cannot practically be reversed back into the original. Before hashing, Keycloak also mixes in a random salt value unique to that particular Credential, ensuring that even if two different users happen to choose the identical password, their stored values look completely different from one another.
Encryption is reversible if you have the right key — which means a stolen encryption key could expose every password at once. Hashing is deliberately one-way: there is no key that turns a stored hash back into the original password. Verification instead works by hashing the newly submitted password the same way and checking whether the two hashes match — the original text is never needed again after the initial setup.
Other Credential types work on the same underlying principle of “verify without exposing,” even though the mechanics differ. A one-time code (OTP) Credential stores a shared secret used to generate matching six-digit codes on both the user’s authenticator app and Keycloak’s side, comparing the two without ever transmitting the secret itself during login. A WebAuthn hardware security key Credential stores a public cryptographic key; the physical key device proves possession by signing a challenge with its private key, which never leaves the device.
What Keycloak Stores
- A one-way hashed-and-salted representation of a password
- A shared secret used only to generate comparable OTP codes
- A public key for hardware security key Credentials
- Metadata: Credential type, creation date, and a user-friendly label
What Keycloak Never Stores
- The original plain-text password, anywhere, at any point after setup
- A reversible copy of any Credential secret
- The private key half of a WebAuthn security key pair
This design means that even if Keycloak’s underlying database were somehow exposed, an attacker would not gain usable passwords directly — they would need to attempt to reverse strong, salted hashes, which is computationally impractical when a modern hashing algorithm and sufficient work factor are used correctly.
DData Flow & Lifecycle
Let’s trace one complete journey — from a user first setting a password, to logging in months later with both a password and a one-time code.
sequenceDiagram
participant U as User
participant KC as Keycloak
participant DB as Credential Store
U->>KC: Set new password
KC-->>KC: Generate random salt
KC-->>KC: Hash password + salt
KC->>DB: Store hash + salt (never the raw password)
Note over U,KC: Weeks later — login attempt
U->>KC: Submit username + password
KC->>DB: Retrieve stored hash + salt
KC-->>KC: Hash submitted password with same salt
KC-->>KC: Compare new hash to stored hash
KC-->>U: Match confirmed — prompt for OTP (second factor)
U->>KC: Submit OTP code from authenticator app
KC-->>KC: Verify code against shared OTP secret
KC-->>U: Both Credentials verified — issue signed token
Fig 2 — Setting a Credential once, verifying it safely every login afterward
Notice the key detail: at no point during the login attempt does Keycloak retrieve or compare a stored plain-text password — it only ever compares hashed values. The original submitted password is discarded from memory immediately after hashing and comparison, and never written to storage in readable form.
Credential Registration
A user sets a password, scans a QR code to register an OTP app, or registers a hardware security key — creating a new Credential record.
Secure Storage
Keycloak hashes and salts the secret (for passwords) or stores the appropriate cryptographic material (for OTP and WebAuthn), never the raw form.
Login Attempt
The user later submits their Credential — a typed password, a generated code, or a hardware key tap — to prove their identity.
Verification
Keycloak performs the appropriate comparison for that Credential type, without ever needing to see or reconstruct the original secret.
Additional Factors (if required)
If the Realm’s Authentication Flow requires more than one Credential, Keycloak repeats verification for each required type in sequence.
Token Issuance
Once every required Credential check succeeds, Keycloak issues a signed token confirming a completed login.
Credential Reset or Removal
A user or administrator can later reset a password, remove a lost security key, or regenerate recovery codes, replacing the old Credential record entirely.
Resetting a password does not automatically remove other registered Credentials, such as an old OTP device or a lost security key. If a user’s phone with an authenticator app is lost or stolen, that OTP Credential should be explicitly removed by an administrator — a password reset alone leaves it active.
EAdvantages, Disadvantages & Trade-offs
Treating every proof type as a first-class Credential gives Keycloak real flexibility, but that flexibility comes with design considerations.
Advantages
- A single user account can hold multiple Credential types, enabling strong multi-factor authentication without custom engineering
- Passwords are never stored in reversible form, limiting damage even if the underlying database were exposed
- Administrators can add or remove individual Credentials (like a lost security key) without disturbing a user’s other proof methods
- New Credential types (such as passkeys) can be adopted without redesigning the entire authentication model
- Per-Realm Authentication Flows let different applications enforce different Credential requirements from the same Keycloak deployment
Disadvantages & Trade-offs
- Supporting many Credential types adds configuration complexity to the Authentication Flow design
- Users can accumulate stale, unused Credentials (like an OTP device they no longer own) if administrators don’t periodically review them
- Weak hashing configuration (an outdated algorithm or too low a work factor) undermines password protection even though the mechanism is sound in principle
- Recovery flows for lost Credentials (a lost hardware key, a lost phone) require careful design to avoid becoming a security bypass themselves
MANY CREDENTIAL TYPES
EVER STORED
= BYPASS RISK
That last row captures a genuine trade-off worth remembering: a Credential system can be cryptographically excellent and still be undermined by a poorly designed recovery path. If “I lost my security key” resets straight to a weak, easily-guessable fallback, an attacker doesn’t need to break any hashing algorithm — they simply exploit the recovery flow instead.
Real Consideration: Recovery Is Part of the Credential System
Security engineers often point out that an authentication system’s real strength is measured by its weakest recovery path, not its strongest Credential type. A Realm that requires a hardware security key for login but allows account recovery through an easily-guessed security question has, in practice, downgraded its security to the level of that question.
FSecurity
Because Credentials are the foundation everything else in Keycloak trusts, their protection deserves particular care.
Strong Hashing Algorithms
Using a modern, deliberately slow hashing algorithm with an appropriately high work factor makes large-scale password guessing computationally expensive, even against a stolen database.
Per-Credential Salting
A unique random salt for every stored password prevents attackers from using precomputed lookup tables to crack many accounts at once.
Multiple Required Credential Types (MFA)
Requiring both a password and a second Credential type means a single stolen secret is not enough on its own to complete a login.
Phishing-Resistant Credential Options
WebAuthn hardware keys and passkeys are cryptographically bound to the legitimate login page, making them resistant to fake login pages in a way typed passwords and even OTP codes are not.
Credential Lifecycle Management
Allowing users and administrators to view, label, and revoke individual Credentials means a lost device or old password can be cleanly removed without affecting other proof methods.
Rate Limiting & Lockout Policies
Limiting how many login attempts can be made in a short window slows down automated password-guessing attacks against any single account.
A well-known real-world risk here is credential stuffing, where attackers take passwords leaked from an unrelated breach elsewhere and try them against many different accounts, betting that some users reused the same password. Because Keycloak never sees or stores a user’s password in reusable form, a breach of Keycloak’s own storage doesn’t hand attackers a working password list — but users reusing passwords across services remains a risk outside Keycloak’s control, which is exactly why MFA matters so much.
Salting and hashing a password is like a bank keeping a note that says “the safe combination, when run through our private calculation, produces this specific number” rather than writing down the combination itself. Even someone who steals that note can’t reconstruct your actual combination from it — they’d have to guess combinations and run the same calculation over and over, which is exactly the slow, expensive process a strong hashing algorithm is designed to force.
Decision
Require a phishing-resistant second Credential (a WebAuthn hardware key or passkey) for privileged accounts, rather than relying on password-plus-OTP alone.
Reasoning
OTP codes can still be relayed by an attacker running a real-time fake login page, while WebAuthn Credentials are cryptographically tied to the legitimate domain and cannot be phished the same way.
Trade-off Accepted
Requires distributing and managing physical or platform-based security keys, in exchange for closing off the most effective real-world account-takeover technique.
GMonitoring, Logging & Metrics
Because every login attempt touches the Credential system, it becomes one of the richest sources of security signal an organization has — if the right things are watched.
Keycloak logs Credential-related events centrally, giving security teams a single place to see password resets, failed verification attempts, new Credential registrations, and Credential removals across the entire user base, rather than reconstructing this history from scattered application logs.
| What Gets Logged | Why It Matters | Example Signal |
|---|---|---|
| Failed Credential verification | Reveals password-guessing or credential-stuffing attempts | 20 failed password attempts on one account in 3 minutes |
| New Credential registration | Tracks when a new proof method (security key, OTP device) is added | New WebAuthn key registered from an unfamiliar device |
| Credential removal | Confirms lost or compromised proof methods are actually revoked | Old OTP device removed after phone was reported lost |
| Password reset events | Highlights account-recovery activity worth reviewing | Password reset requested twice in one day |
| MFA challenge outcomes | Distinguishes routine logins from suspicious second-factor denials | OTP prompt repeatedly denied by the legitimate user |
A burst of failed Credential verifications against a single account, especially followed immediately by a successful login, is a pattern worth flagging — it can indicate a successful guessing attempt or a leaked password being tried for the first time.
These logs also support compliance obligations that require organizations to demonstrate how account access is proven and protected. Because Credential events are centralized in Keycloak, producing that evidence is far simpler than reconstructing authentication history from many separate application login systems.
HDesign Patterns & Anti-patterns
Years of real-world Keycloak deployments have surfaced Credential-handling approaches that hold up well, and habits that reliably cause problems.
Layered Credential Requirements
Requiring stronger Credential combinations (password plus hardware key) for sensitive actions, while allowing lighter requirements for low-risk, everyday access.
Self-Service Credential Management
Letting users view, label, and remove their own registered Credentials (such as old OTP devices) reduces administrative burden while keeping users in control of their own security.
Progressive Credential Upgrades
Prompting existing users to register a stronger Credential type (like a passkey) over time, rather than forcing an abrupt, disruptive migration for the entire user base at once.
Consistent, Reviewed Recovery Flows
Designing account-recovery paths with the same security rigor as the primary login, so recovery never becomes the weakest link in the system.
Anti-pattern: Weak Recovery Bypassing Strong Login
- Requiring a hardware key for normal login, but allowing recovery through an easily-guessed security question
- Letting “forgot password” flows skip MFA entirely, undermining the very protection MFA was meant to provide
- Treating recovery as an afterthought rather than as a core part of Credential security design
Anti-pattern: Credential Accumulation Without Review
- Allowing old, unused OTP devices and security keys to remain registered indefinitely without periodic review
- Never prompting users to remove Credentials tied to devices they no longer own
- Leaving a growing number of forgotten, unreviewed proof methods attached to sensitive accounts
One especially instructive anti-pattern is what security teams sometimes call “MFA theater” — an organization proudly enables multi-factor authentication for login, while leaving a password-only recovery flow completely unprotected. Attackers quickly learn to skip the hardened front door entirely and walk straight through the unguarded recovery path instead.
IBest Practices & Common Mistakes
A practical checklist distilled from real deployments — the habits that keep a Credential system trustworthy over time.
Require Multiple Credential Types for Sensitive Accounts
Password alone should never be treated as sufficient for privileged or high-value accounts — pair it with an OTP or hardware key.
Use Strong, Modern Hashing Configuration
Ensure the hashing algorithm and work factor used for password storage are kept current with security best practice, not left at outdated defaults.
Design Recovery Flows as Carefully as Login
Apply the same rigor to “forgot password” and Credential-recovery paths as to the primary Authentication Flow — recovery is a security boundary too.
Periodically Review Registered Credentials
Prompt users, or have administrators check, for old OTP devices or security keys tied to hardware they no longer possess.
Remove Lost or Compromised Credentials Promptly
Don’t rely on a password reset alone to fully secure an account — explicitly remove any other Credential tied to a lost device.
Prefer Phishing-Resistant Options Where Practical
Encourage adoption of WebAuthn hardware keys or passkeys over SMS or basic OTP codes wherever the user base can support it.
Assuming a password reset alone fully secures a compromised account. If the account also has a registered OTP device or security key the attacker doesn’t control, this is fine — but if the attacker registered their own additional Credential during the compromise, a password reset alone leaves that second Credential active.
Leaving default hashing settings unreviewed for years. What counted as a strong work factor when a system was first configured can become comparatively weak as computing power increases, so hashing configuration deserves periodic revisiting, not a “set once and forget” treatment.
JReal-World & Industry Examples
Keycloak Credentials aren’t a theoretical concept — they’re quietly proving identity behind real deployments across many industries.
Financial Services Applications
Banking and fintech platforms commonly require password-plus-OTP or password-plus-hardware-key Credential combinations for account access, reflecting regulatory expectations around strong customer authentication for financial transactions.
Enterprise Workforce Accounts
Large organizations frequently require employees to register a WebAuthn security key or platform passkey as a second Credential alongside their password, particularly for accounts with access to sensitive internal systems.
Consumer Applications with Passwordless Options
Many modern consumer platforms now offer passkeys — a Credential type that replaces the password entirely with a cryptographic key tied to the user’s device — reducing reliance on memorized secrets altogether while remaining compatible with Keycloak’s Credential model.
Government and Healthcare Portals
Public-sector and healthcare systems often mandate multi-factor Credential combinations by policy, given the sensitivity of the records involved, making Keycloak’s flexible, per-Realm Authentication Flow configuration a natural fit for meeting those requirements.
A particularly instructive real-world lesson comes from large-scale credential-stuffing incidents reported across the industry: attackers rarely need to break a strong hashing algorithm directly. Instead, they exploit reused passwords from unrelated breaches, or target weak recovery flows. This consistently reinforces why MFA and careful recovery-path design matter as much as, if not more than, the strength of the primary hashing mechanism itself.
KFrequently Asked Questions
LSummary and Key Takeaways
A quick recap of everything this guide has covered — the mental model to carry forward.
A Credential in Keycloak is the stored proof behind every login — a password, an OTP registration, a security key, or any other verifiable evidence of identity. Keycloak never stores these secrets in reversible form; it stores protected representations that can be checked but not read back. A single user can carry multiple Credentials at once, enabling layered, multi-factor authentication without custom engineering — but the real-world strength of that system depends just as much on how carefully recovery flows and Credential lifecycle management are handled as on the cryptography itself.
Key Takeaways
- A Credential is the proof, not the permission: it answers “who are you,” while Roles and Groups separately answer “what can you do.”
- Passwords are never stored in reversible form: Keycloak keeps only a salted, one-way hashed representation, checked by re-hashing each login attempt.
- Different Credential types use different protection mechanisms, but all share the same principle — verify without exposing the underlying secret.
- A single user can hold multiple Credentials at once, making multi-factor authentication a natural extension of the same model rather than a bolt-on feature.
- Recovery paths are part of the Credential system, and a weak recovery flow can undermine even the strongest primary login method.
- Credential lifecycle management matters: lost devices and old, unused Credentials should be reviewed and removed, not left to accumulate.
- Phishing-resistant options like WebAuthn and passkeys offer stronger real-world protection than passwords or OTP codes alone, especially for sensitive accounts.