Overview
The password strategy provides:- Registration with password credentials
- Login with identifier and password
- Password update and change functionality
- Built-in password validation and breach detection
- Support for password migration hooks
Configuration
Enable password authentication
Add the password method to your Kratos configuration:kratos.yml
Password validation
Kratos includes a default password validator that:- Checks password length (minimum 8 characters recommended)
- Validates password against haveibeenpwned.com using k-anonymity
- Ensures password is not too similar to the identifier
- Prevents common password patterns
selfservice/strategy/password/validator.go:59-90 and uses:
- Troy Hunt’s haveibeenpwned API for breach detection
- Levenshtein distance to compare password with identifier
- Longest common substring analysis
Password hashing
Configure the password hashing algorithm:kratos.yml
bcrypt(recommended)argon2(more secure, more resource intensive)
Identity schema configuration
Basic password configuration
Define which trait serves as the identifier for password authentication:identity.schema.json
The field marked with
"identifier": true will be used as the username for login.Multiple identifiers
You can configure multiple fields as identifiers:identity.schema.json
User flows
Registration flow
Login flow
Password update
Users can update their password through the settings flow:Security considerations
Password policy
While Kratos provides default validation, you should:- Enforce minimum password length (8+ characters recommended)
- Use the breach detection feature (enabled by default)
- Consider implementing rate limiting on login attempts
- Enable account recovery flows
Breach detection
Kratos automatically checks passwords against the haveibeenpwned.com database using k-anonymity:- Only the first 5 characters of the password hash are sent
- No plain-text passwords leave your infrastructure
- Validates against known breached passwords
selfservice/strategy/password/validator.go:93-95.
Password migration
If migrating from another system, you can use password migration hooks:kratos.yml
UsePasswordMigrationHook flag in credentials (see selfservice/strategy/password/strategy.go:91-92).
API reference
Strategy implementation
The password strategy is implemented as:- Strategy ID:
password(asidentity.CredentialsType) - Node Group:
passwordgroup in UI nodes - AAL Level: AAL1 (first factor authentication)
selfservice/strategy/password/strategy.go:78-80 for the strategy structure.
Configuration options
Next steps
- Learn about Multi-factor authentication
- Configure Account recovery
- Set up Email verification