What Is Username/Password Authentication in Keycloak?
The oldest, most familiar login method in the world — and still the default building block every Keycloak authentication flow starts from.
Before there was social login, biometrics, or passkeys, there was the humble username and password — and it’s still, by far, the most widely deployed way of proving identity on the internet. In Keycloak, this method isn’t hardcoded or hidden away; it’s an explicit, configurable building block inside Keycloak’s Authentication Flows engine. Understanding exactly how username/password authentication works inside Keycloak — what happens the instant someone submits a login form — gives you the foundation for understanding everything more advanced Keycloak offers, from MFA to passwordless login. This guide walks through it end to end.
ACore Concepts: What Exactly Is Username/Password Authentication?
Username/Password Authentication is the process of confirming a user’s identity by asking them to type two pieces of information they should be the only ones to know (or that identify them): a username (or email) that identifies which account they’re claiming to be, and a password — a secret string only that account holder should know — that proves they’re really that person.
In Keycloak, this isn’t a single hardcoded feature bolted onto the login page. It’s actually one configurable step, called an Authenticator, inside a larger, fully customizable pipeline called an Authentication Flow. The default flow most users experience — called the Browser Flow — includes a step commonly labeled “Username Password Form”, which is exactly the piece responsible for rendering the login form and checking what’s typed into it.
Think of a hotel check-in desk. You state your name (the username) and show a piece of ID that only matches if it’s really you (the password, functioning as your proof). The front-desk clerk compares what you present against the reservation records — they don’t need to know your entire life story, just enough to confirm you are who you claim to be for this one specific check-in step.
What makes this deceptively simple flow interesting under the hood is everything Keycloak does around that basic check: hashing and never storing raw passwords, enforcing password policies, detecting brute-force attempts, supporting federated directories, and seamlessly chaining into further steps like multi-factor authentication — all without the application itself needing to implement any of that logic.
Username/Password authentication is just one step inside a Keycloak Authentication Flow, not the entire login process by itself. A single flow can chain this step together with an OTP step, a WebAuthn step, or conditional logic — meaning “logging in with a password” and “logging in securely” are related but not identical ideas in Keycloak’s model.
It’s also worth knowing where the password itself might actually be checked. If the user is a local Keycloak user, the password is verified against a securely hashed value stored in Keycloak’s own database. If the user is a federated user (synced from LDAP or Active Directory), Keycloak instead forwards the check to that external directory in real time — the username/password step behaves identically from the user’s point of view either way, even though very different machinery runs behind it.
BArchitecture & Core Components
flowchart TB
LoginForm["Login Form (Username Password Form)"] --> AuthFlow["Authentication Flow (e.g. Browser Flow)"]
AuthFlow --> CredProvider["Credential Provider"]
CredProvider --> LocalDB["Local Password Hash Store"]
CredProvider --> LDAPProvider["LDAP / AD Federation Provider"]
AuthFlow --> PasswordPolicy["Password Policy Engine"]
AuthFlow --> BruteForce["Brute Force Detection"]
AuthFlow -->|"on success"| NextStep["Next Flow Step (e.g. OTP)"]
Let’s walk through each labeled piece in turn.
Authentication Flow
A named, ordered sequence of steps a login attempt must pass through. Keycloak ships with sensible defaults (like the Browser Flow) but lets administrators fully customize the sequence — reordering steps, marking some as required versus optional, or adding conditional branches.
Username Password Form (the Authenticator)
The specific execution step responsible for rendering the actual login form and capturing what’s submitted. It doesn’t do the cryptographic verification itself — it hands the submitted credentials off to the appropriate Credential Provider.
Credential Provider
The component that actually performs the comparison. For local users, it retrieves the stored password hash and checks it using the same hashing algorithm and parameters used when the password was originally set. For federated users, it delegates the check outward instead.
Password Policy Engine
A configurable set of rules — minimum length, required character types, not matching the username, not reusing recent passwords, expiration after a set number of days — enforced whenever a password is created or changed, though not on every single login check itself.
Brute Force Detection
A safeguard that monitors failed login attempts per user and can temporarily lock an account after too many consecutive failures, slowing down automated password-guessing attacks.
People sometimes assume the “Username Password Form” step is the entire login system. In reality it’s one interchangeable piece — administrators can add MFA steps after it, replace it with passwordless alternatives, or even reorder it relative to identity-provider steps, all without touching application code.
CHow Username/Password Checking Works Internally
Hashing, Not Encryption
Keycloak never stores a password in a way that could be reversed back into the original text. Instead, when a password is set, it’s run through a one-way hashing algorithm (by default a strong, iterated algorithm like PBKDF2, configurable via the realm’s Password Policy) combined with a unique random salt per user. Only the resulting hash and salt are stored — the original password is discarded immediately after hashing.
The Verification Step
When a user submits a password at login, Keycloak doesn’t “decrypt” anything — it re-runs the exact same hashing process on the submitted password, using the stored salt, and compares the newly computed hash to the one stored on file. If they match exactly, the password is considered correct; if not, authentication fails.
Imagine a sealed wax stamp instead of a written signature. You can’t “read backwards” from a wax seal to recover the original stamp used to make it, but you can press a new stamp and compare the two impressions side by side to see if they match. Password hashing works the same way — comparison without reversal.
Federated Verification
For users sourced from LDAP or Active Directory, Keycloak typically doesn’t store or hash the password locally at all. Instead, it performs what’s called an LDAP bind operation — attempting to authenticate directly against the external directory server using the submitted credentials — and treats a successful bind as a successful password check.
Required Actions Triggered by This Step
A successful username/password check can still be followed by a mandatory extra step if the user’s account carries a Required Action, such as “Update Password” (often set after an admin-initiated reset) — the user is fully authenticated in terms of “who they are,” but blocked from proceeding until that required step is completed.
Password Policies are enforced when a password is created or changed — not re-checked against every historical password on every single login. This is why changing a policy (say, increasing minimum length) doesn’t retroactively invalidate existing passwords that were valid under the old rules; it only applies going forward.
DData Flow & the Login Lifecycle
flowchart LR
A["1. User submits username + password"] --> B["2. Keycloak locates the User record"]
B --> C["3. Determine source: local or federated"]
C --> D["4. Local: compare password hash"]
C --> E["5. Federated: attempt LDAP bind"]
D --> F["6. Check brute-force lockout status"]
E --> F
F --> G["7. Resolve pending Required Actions"]
G --> H["8. Proceed to next flow step (e.g. OTP) or issue token"]
Form Submission
The user enters their username and password into the Keycloak-hosted login page and submits it.
User Lookup
Keycloak resolves the submitted username or email to a specific User record within the current realm.
Lockout Check
Before even checking the password, Keycloak checks whether this account is currently locked out due to too many recent failed attempts.
Credential Verification
The password is verified — either by hash comparison for a local user, or via a live LDAP bind for a federated one.
Required Action Resolution
Any pending Required Actions on the account (like a forced password reset) are surfaced and must be completed before proceeding.
Flow Continuation or Token Issuance
If this was the final step in the Authentication Flow, a signed token is issued. If more steps remain (like an OTP prompt), the user proceeds to them next.
Notice that a “successful” username/password check doesn’t necessarily mean the login is complete — it simply means that one specific step in a potentially longer flow has passed. This is exactly what makes layering additional factors on top of username/password authentication so seamless in Keycloak.
EAdvantages, Disadvantages & Trade-offs
Advantages
- Universally familiar — virtually every user already knows how to use it, with zero learning curve.
- Works without any special hardware, app, or device requirement, unlike biometrics or hardware keys.
- Simple to integrate as the baseline step in any Authentication Flow, including as a fallback for more advanced methods.
- Fully compatible with existing federated directories (LDAP/AD) many organizations already operate.
Disadvantages / Trade-offs
- Passwords are frequently reused across services, so a breach elsewhere can compromise an otherwise well-protected account.
- Vulnerable to phishing — a convincing fake login page can trick users into typing credentials directly to an attacker.
- Weak or predictable passwords remain common unless policy and user education actively counter that tendency.
- On its own, without MFA, it’s widely considered insufficient protection for anything genuinely sensitive today.
A password is like a house key made of a shape only you’re supposed to know. It’s simple and works everywhere — but if someone copies that shape (through phishing or reuse), your door offers no further resistance at all. That’s precisely why security-conscious homeowners add a second lock rather than relying on one key alone — the same reasoning behind pairing passwords with MFA.
FSecurity Considerations
Strong Hashing Configuration
Keycloak’s realm-level Password Policy lets administrators configure the hashing algorithm and its iteration count, allowing organizations to keep pace with evolving cryptographic best practices as computing power increases over time.
Brute-Force Protection
Enabling Brute Force Detection at the realm level automatically locks out an account, or introduces increasing delays, after a configurable number of consecutive failed attempts — a critical defense against automated password-guessing and credential-stuffing attacks.
Password Policies Beyond Length
Beyond minimum length, Keycloak’s Password Policy engine can enforce a mix of character types, block reuse of recent passwords, forbid the password from containing the username, and require periodic expiration — each configurable independently per realm.
Relying on username/password alone for anything sensitive — an admin console, financial data, production infrastructure — leaves a single point of failure that phishing, reuse, or a leaked breach database can defeat. Combining this step with an OTP, WebAuthn, or conditional risk-based step inside the same Authentication Flow closes that gap without requiring separate application-level work.
Transport Security
Credentials must always travel exclusively over HTTPS between the browser and Keycloak — without this, the password (or any token issued afterward) could be intercepted in transit regardless of how strong the hashing or policy configuration is on the server side.
The Idea
Chain a second authenticator — OTP, WebAuthn, or a conditional step based on risk signals — directly after the Username Password Form step within the same Authentication Flow.
Why It Matters
Even if a password is fully compromised through phishing or reuse, the attacker still cannot complete the second factor, meaningfully reducing the practical impact of a leaked or guessed password.
GDesign Patterns & Anti-Patterns
Good Pattern: Layer MFA on Top
Treat username/password as the first, familiar step in a flow, not the entire flow — pairing it with a second factor for any realm handling meaningful access or sensitive data.
Good Pattern: Conditional Flow Branching
Use Keycloak’s conditional flow steps to require stronger verification only when risk signals warrant it — for example, demanding MFA for logins from unrecognized devices while keeping trusted, recognized ones frictionless.
Good Pattern: Federate Rather Than Duplicate
When an organization already has an authoritative LDAP/AD directory, federating username/password checks to it (rather than migrating everyone to local Keycloak accounts) keeps password policy enforcement consistent with existing corporate standards.
What It Looks Like
Leaving the default Browser Flow’s single-factor username/password step unchanged for highly privileged accounts, such as Master Realm administrators.
Why It’s a Problem
The most powerful accounts in the entire system end up protected by the weakest available authentication method, precisely where the consequences of compromise are most severe.
What It Looks Like
Leaving the realm’s Password Policy at permissive defaults purely to reduce user friction during account creation.
Why It’s a Problem
Weak, unenforced policies make automated password-guessing dramatically more effective across an entire user base, undermining every other security control layered on top.
HBest Practices & Common Mistakes
Enable Brute Force Detection
Turn on account lockout protections at the realm level rather than leaving login attempts entirely unthrottled.
Set a Meaningful Password Policy
Configure minimum length, complexity, and reuse rules deliberately, balanced against genuine usability rather than copying defaults blindly.
Chain a Second Factor
Add an OTP or WebAuthn step after the password step for any realm handling sensitive data or privileged access.
Use Required Actions for Resets
Force password updates through the built-in Required Action mechanism after admin-initiated resets, rather than manual out-of-band communication.
Common Mistakes to Avoid
- Leaving Brute Force Detection disabled: This is off by default in some setups and must be deliberately enabled to take effect.
- Assuming HTTPS is “someone else’s problem”: Misconfigured deployments that allow plain HTTP for the login form expose every submitted password in transit.
- Not testing federated login failure modes: If the external LDAP/AD server is unreachable, federated username/password checks will fail — a scenario worth explicitly planning and monitoring for.
- Copying password policy settings between realms without review: A policy appropriate for a low-risk customer realm may be far too weak for an internal administrative realm.
IReal-World & Industry Examples
Enterprise Employee Portals: Password + Federation + MFA
Large organizations commonly configure their employee-facing realm to check passwords against an existing Active Directory via federation, immediately followed by an OTP or push-notification step for every login — combining familiar credentials with strong second-factor protection.
Customer-Facing SaaS Products: Password + Optional MFA
Consumer-facing platforms often keep the default username/password step as the primary login method, while offering MFA as an optional, user-enabled enhancement rather than mandating it for every account, balancing security with signup friction.
Regulated Industries: Mandatory Strong Password Policy
Organizations in finance or healthcare frequently configure strict Password Policies — long minimum length, mandatory character variety, and periodic expiration — directly through Keycloak’s realm settings to satisfy compliance requirements without any custom application code.
JFrequently Asked Questions
KSummary & Key Takeaways
Key Takeaways
- Username/Password Authentication in Keycloak is a configurable step — the “Username Password Form” authenticator — inside a larger Authentication Flow, not a fixed, standalone feature.
- Passwords are never stored in plain text; Keycloak stores a salted hash and re-computes it for comparison on every login attempt.
- Local users are checked against Keycloak’s own hash store, while federated users are checked live against an external LDAP/Active Directory server.
- Brute Force Detection and configurable Password Policies provide layered protection specifically around this authentication step.
- Because password-only authentication remains vulnerable to phishing and reuse, best practice pairs it with a second factor for any sensitive or privileged access.
- Its flexibility — reorderable, replaceable, and chainable within Keycloak’s flow engine — is what allows organizations to evolve from simple passwords toward MFA or fully passwordless authentication without rewriting application code.