One-time code format
Ory Kratos Identities sends one-time codes to a user's email address or phone number during login, registration, verification, and account recovery, and when the code method is used as a second factor. By default, each code has six digits.
You can change the format of these codes with two settings:
lengthsets the number of characters in a code. It must be between6and20. The default is6.alphabetsets the characters a code is made of:digitsuses the digits0to9. This is the default.alphanumericuses lowercase letters and digits, without characters that are easy to confuse, such as0andoor1andl. Users can enter these codes in uppercase or lowercase.
A longer code, or one that includes letters, is harder to guess but takes users longer to type. The format applies to codes sent after you change it. Codes sent earlier stay valid until they expire.
- Ory CLI
- Self-hosted
-
Download the Ory Kratos Identities config from your project and save it to a file:
## List all available workspacesory list workspaces## List all available projectsory list projects --workspace <workspace-id>## Get configory get identity-config --project <project-id> --workspace <workspace-id> --format yaml > identity-config.yaml -
Set the code format:
identity-config.yamlselfservice:methods:code:config:length: 12alphabet: alphanumeric -
Update the Ory Kratos Identities configuration using the file you worked with:
ory update identity-config --project <project-id> --workspace <workspace-id> --file identity-config.yaml
Set the code format in the Ory Kratos Identities configuration file:
selfservice:
methods:
code:
config:
length: 12
alphabet: alphanumeric
User interface
The code input node in the flow's UI carries attributes that match the configured format:
maxlengthis the code length.patternaccepts only characters of the configured alphabet. It doesn't check the length, so the flow reports a code that is too short as invalid.inputmodeisnumericfor digit codes andtextfor alphanumeric codes, so mobile devices show the right keyboard.
Ory Elements and Ory Account Experience show one box per character for codes of up to eight characters, and a single text field for longer codes. If you build your own UI, render these attributes on the code input.
If your custom email or SMS templates describe the code, for example as a six-digit code, update the text to match the new format.