---
schema_version: "1"
id: 14fe5b4b7f3317e7b1d52c6befa8732ef3b82bb91d328b1f5bab7e673f5e5ef2
title: Customize the Apex Login Controller
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/experience/264-0-0/external_identity_customize_login_controller.md
canonical_url: https://help.salesforce.com/s/articleView?id=experience.external_identity_customize_login_controller.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 626f08a5508668d4648da015474ffdfd20ab4e2aea12fd86a37cb6b7f318a02c
description: Salesforce provides an easy way to customize your login process using the Login Discovery Page, which lets you implement passwordless login. However, if you want even more control over your login process, you can modify the Apex login controllers and use customized Visualforce pages.
products:
  - Experiences
release: "264"
---
# Customize the Apex Login Controller

Salesforce provides an easy way to customize your login process using the Login Discovery Page, which lets you implement passwordless login. However, if you want even more control over your login process, you can modify the Apex login controllers and use customized Visualforce pages.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: Salesforce Classic and Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: <strong>Enterprise</strong>, <strong>Performance</strong>, <strong>Unlimited</strong>, and <strong>Developer</strong> Editions</td></tr></tbody></table>

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:center;vertical-align:top;" id="d42146e70">User Permissions Needed</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d42146e70 ">To create and edit Visualforce pages:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d42146e70 ">Customize Application</td>

          </tr>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d42146e70 ">To edit Apex classes:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d42146e70 ">
              <p>Author Apex</p>
              <p>AND</p>
              <p style="margin-bottom:0;">Customize Application</p>
            </td>

          </tr>
        </tbody>
      </table>

You can use these steps to customize the login process for Default, Experience Builder, and Visualforce Pages. If you're using the Login Discovery Page to implement passwordless login programmatically, see [Email or Phone Number Registration with Passwordless Login](https://help.salesforce.com/s/articleView?id=experience.external_identity_passwordless_login_in_apex.htm&type=5&language=en_US).

For more information on Login Pages, see [Login Page Types](https://help.salesforce.com/s/articleView?id=xcloud.external_identity_login_discovery_login_types.htm&type=5&language=en_US).

1. From Setup, in the Quick Find box, enter Apex Classes, and then select **Apex Classes**.
2. Next to `CommunitiesLoginController`, click **Edit**.
3. Add the following code.
    
    ```java
    global PageReference forwardToCustomAuthPage() {
            String startUrl = System.currentPageReference().getParameters().get('startURL');
            return new PageReference(Site.getPathPrefix() + '/SiteLogin?startURL=' + EncodingUtil.urlEncode(startURL, 'UTF-8'));
        }
    ```
4. If you created a custom login page, replace `SiteLogin` with the name of your Visualforce page.
5. Click **Save**.
6. Click **Edit** next to `CommunitiesLandingController`.
7. Add this code.
    
    ```java
    public PageReference forwardToCustomAuthPage() {
            String startUrl = System.currentPageReference().getParameters().get('startURL');
            return new PageReference(Site.getPathPrefix() + '/SiteLogin?startURL=' + EncodingUtil.urlEncode(startURL, 'UTF-8'));
        }
    ```
8. If you created a custom login page, replace `SiteLogin` with the name of your Visualforce page.
9. Click **Save**.
10. From Setup, enter Visualforce Pages in the Quick Find box, then select **Visualforce Pages**.
11. Click **Edit** next to `CommunitiesLogin`.
12. In the first line of code, add the following:
    
    ```
    action="{!forwardToCustomAuthPage}"
    ```
13. Click **Save**.
14. Click **Edit** next to `CommunitiesLanding`.
15. In the first line of code, add the following:
    
    ```
    action="{!forwardToCustomAuthPage}"
    ```
16. Click **Save**.