OTP Policy Settings
- Type
- Reference
- For
- Keycloak administrators
- Checked against
- Keycloak 26.8.2
- Owner
- Karan Deshmukh
- Last review
- 2026-11-27
A realm's OTP policy decides what a one-time password (OTP) looks like in it: how long a code lasts, how many digits it has, and how much clock difference Keycloak forgives. In the admin console, it's under Authentication > Policies > OTP Policy.

Settings
The defaults are those of a new realm in Keycloak 26.8.2.
| Setting | Default | What it decides |
|---|---|---|
| OTP type | Time based | A time-based code changes every period. A counter-based code changes each time the user asks the app for one. |
| OTP hash algorithm | SHA1 | The algorithm the app and Keycloak use to compute a code. |
| Number of digits | 6 | The length of a code: 6 or 8. |
| Look around window | 1 | How many periods before and after the current one Keycloak also accepts. |
| OTP Token period | 30 seconds | How long a time-based code lasts. |
| Supported applications | FreeOTP, Google Authenticator, Microsoft Authenticator | The apps that Mobile Authenticator Setup lists for users to install. |
| Reusable token | Off | Whether a code that has signed someone in works again before it expires. |
Admin REST API Fields
Each setting is a field of the realm representation, at GET /admin/realms/{realm}.
| Field | Default |
|---|---|
otpPolicyType | totp |
otpPolicyAlgorithm | HmacSHA1 |
otpPolicyDigits | 6 |
otpPolicyLookAheadWindow | 1 |
otpPolicyPeriod | 30 |
otpPolicyCodeReusable | false |
otpPolicyInitialCounter | 0, used only by counter-based codes |
Before You Change a Setting
A change applies only to authenticators set up after it. Each OTP credential keeps the type, digits, period and algorithm it was set up with: after a change from 6 to 8 digits, a phone set up before the change still signed in with 6-digit codes. To move a user to the new policy, reset their one-time password. To move many users, reset them with the admin REST API.