Skip to main content
Password authentication is the traditional method where users authenticate with an identity field (typically email or username) and a password.

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, the email 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.
Example configuration:
With multiple identity fields, users can authenticate using any of them:

Authentication endpoint

Request body:
Leave identityField empty for automatic detection, or specify a particular field from your identityFields configuration.
Successful response (200):

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:

Email change flow

Authenticated users can change their email address:
1

Request email change

This endpoint requires authentication. Include the auth token in the Authorization header.
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

Password authentication endpoints are rate-limited to prevent brute force attacks. Implement additional security measures like account lockouts for production applications.

Best practices

  1. Require email verification: Set your collection’s authRule to "verified = true" to allow only verified users to authenticate.
  2. Use strong password requirements: Configure password field validators with minimum length and complexity requirements.
  3. Enable MFA: For sensitive applications, enable multi-factor authentication to add an extra layer of security.
  4. Monitor failed login attempts: Use the activity log to track failed authentication attempts.
  5. Rotate token secrets: Periodically update your token configuration secrets for enhanced security.

Custom authentication hooks

You can customize the authentication behavior using event hooks:

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