Configuration
You can configure password authentication in your auth collection settings:Identity fields
Identity fields are the field names that can be used to identify a user during authentication. By default, theemail field is used, but you can configure any field with a unique index.
Only fields with a single-column UNIQUE index are accepted as identity fields. This ensures that each identity is unique across your collection.
Authentication endpoint
Leave
identityField empty for automatic detection, or specify a particular field from your identityFields configuration.Password validation
PocketBase provides built-in password validation through the Record model:Setting passwords
You can set passwords programmatically using the Record methods:SetRandomPassword() generates a ~30 character password and sets it directly as a hash, bypassing field validators. This is useful for OAuth2 or OTP user flows where a password is needed but won’t be used for authentication.Password reset flow
PocketBase provides a secure two-step password reset process:1
Request password reset
User submits their email to request a password reset.
The endpoint always returns 204 No Content to prevent email enumeration attacks.
2
Receive reset email
User receives an email with a password reset link containing a token.
3
Confirm password reset
User submits the token and new password to complete the reset.
Rate limiting
Password reset requests are rate-limited to prevent abuse. Users can only request a password reset once every 2 minutes:Email verification
Users can verify their email addresses through a similar two-step process:- Request verification
- Confirm verification
Email change flow
Authenticated users can change their email address:1
Request email change
2
Confirm email change
Implementation details
The password authentication implementation in PocketBase follows this logic:Case-insensitive identity lookup
PocketBase supports case-insensitive identity field lookup based on the index collation:Security considerations
Best practices
-
Require email verification: Set your collection’s
authRuleto"verified = true"to allow only verified users to authenticate. - Use strong password requirements: Configure password field validators with minimum length and complexity requirements.
- Enable MFA: For sensitive applications, enable multi-factor authentication to add an extra layer of security.
- Monitor failed login attempts: Use the activity log to track failed authentication attempts.
- Rotate token secrets: Periodically update your token configuration secrets for enhanced security.
Custom authentication hooks
You can customize the authentication behavior using event hooks:Related topics
OAuth2 authentication
Set up social login as an alternative
OTP authentication
Enable passwordless authentication
MFA
Add multi-factor authentication
API rules
Configure access control rules