+ Start a Discussion

Custom Login Page



Has anyone built Custom login page and authenticated user to Salesforce ? If the user is valid then land user on home page.


thanks in advance

Edwin VijayEdwin Vijay

One way is by passing parameters through the URL.. I guess it is http://login.salesforce.com?uname=blah&pwd=blah but this would not ensure error handling


For a login page, create a custom component of login.


Tryout the sample code given below :


VF Component:

<apex:component access="global" controller="StLoginCntlr">
<apex:form  forceSSL="true">
<apex:actionFunction action="{!login}"></apex:actionFunction>
<p><a class="rover link_login">Login</a></p>
    <div class="container-full">
    <p class="form-item"><label for="">Username</label>&nbsp;&nbsp;
    <apex:inputText value="{!username}" styleClass="form-text width-217" />
    <p class="form-item"><label for="">Password</label>&nbsp;&nbsp;
    <apex:inputSecret value="{!password}" styleClass="form-text width-217" />
    <p class="align-center">
    <apex:commandbutton action="{!login}" value="Login" id="loginButton" styleClass="form-submit"/>
function ShowE(){
var msgE = "{!IF(NOT(ISNULL(propMessage)),propMessage,'')}";
if(msgE != null && msgE != "") alert(msgE);
function onKeyup_TxtFieldcom(e)
        var keynum;
        if(window.event) // IE
                keynum = e.keyCode;
        if(keynum == 13)
                return false;  

Controller code:

public class StLoginCntlr {
public StLoginCntlr() {}
public transient String strMsg = '';
public String username {get; set;}
public String password {get; set;}
public String propMessage  { get {return strMsg;} set{strMsg = value;} }
public PageReference login()
    String startUrl = '/apex/testconfirm';
    PageReference pr = Site.login(username, password, startUrl);
    system.debug('---------  KKKKKK  --- ' + ApexPages.hasMessages());
             ApexPages.Message[] apm = ApexPages.getMessages();
             for(ApexPages.Message am : apm)
                     if(strMsg != null && strMsg != '')
                             strMsg = strMsg + '  ' + am.getSummary();
                             strMsg = am.getSummary();
            strMsg = '';
    username = '';
    password = '';
    return pr;


Hope this helps.



Iam new to Salesforce, I have a similar requirement. I need to develop a new custom login page with our company logo instead of salesforce Logo's in the Login Page.

Pradeep.... can you explain me what to do after creating this component. Do we need to develop any VF page using this component.

Can anyone post a VF page for the custom login page.


Mandeep DekaMandeep Deka

Hi avtopi786,


Check out this link Custom Salesforce Login


I have customized it further to use it according to my requirement. The Sites page is available publicly and with the right credentials, a authenticated user can log in and land on the home page of Salesforce. 


Now my challenge is that anyone trying to log in outside my network is unable to log in because his/her IP address is not entered in my Trusted IP Ranges. Moreover, if he/she has to be able to logged in from other network must use the security token appended to the password. I am able to display to the user the error message based on whether the credentials were incorrect or the network is out of the trusted networks and need to use the security token.


But how do I overcome this challenge now. There are two options:


1. Either the user's IP Address is already added in my trusted IP ranges before hand or

2. the user has access to the Security token from some other public source provided to him/her before hand.


Option 1 is not possible as users might try to access from any network when he is on the move.


Any ideas SF guys?



Mandeep Deka


I want create custom login page using visualforce .So could you plz help me