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.
You can set passwords programmatically using the Record methods:
// Set a user-provided passwordrecord.SetPassword("user_password")// Set a random password (for OAuth2/OTP users)randomPassword := record.SetRandomPassword()
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.
The password authentication implementation in PocketBase follows this logic:
// From apis/record_auth_with_password.gofunc recordAuthWithPassword(e *core.RequestEvent) error { collection, err := findAuthCollection(e) if err != nil { return err } if !collection.PasswordAuth.Enabled { return e.ForbiddenError( "The collection is not configured to allow password authentication.", nil) } // Bind and validate form data form := &authWithPasswordForm{} if err = e.BindBody(form); err != nil { return e.BadRequestError( "An error occurred while loading the submitted data.", err) } // Find record by identity field var foundRecord *core.Record for _, name := range collection.PasswordAuth.IdentityFields { foundRecord, err = findRecordByIdentityField( e.App, collection, name, form.Identity) if err == nil { break } } // Validate password if foundRecord == nil || !foundRecord.ValidatePassword(form.Password) { return e.BadRequestError( "Failed to authenticate.", errors.New("invalid login credentials")) } return RecordAuthResponse(e, foundRecord, core.MFAMethodPassword, nil)}
Password authentication endpoints are rate-limited to prevent brute force attacks. Implement additional security measures like account lockouts for production applications.