function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sam1980Sam1980 

Login attempt failed :: Authenticating Users on Force.com Sites - Visual Force Site

I used this tutorial from https://developer.salesforce.com/page/Authenticating_Users_on_Force.com_Sites to create a Login page in Visualforce with Username & Password fields and Buttons to have are: SAVE, CANCEL.

I have tried but login fails. Showing error as: Error: Your login attempt has failed. Make sure the username and password are correct.

Here is the Visualforce markup for this page, in this case the source we are reviewing it is a component that is placed on the login page that you create within your site.

<apex:component controller="SiteLoginController" id="loginComponent">
    <apex:form id="loginForm" forceSSL="true">
        <apex:outputPanel layout="block">
            <apex:pageMessages id="error" />
            <apex:panelGrid columns="2" style="margin-top:1em;">

                <apex:outputLabel value="{!$Label.site.username}" for="username" />
                <apex:inputText id="username" value="{!username}" />
                <apex:outputLabel value="{!$Label.site.password}" for="password" />
                <apex:inputSecret id="password" value="{!password}" />

                <br />
                <apex:commandButton action="{!login}"
                    value="{!$Label.site.login_button}" id="loginButton" />
                <br />
                <apex:panelGroup id="theLinks">

                    <apex:outputLink value="{!$Page.ForgotPassword}">
                        {!$Label.site.forgot_your_password_q}
                    </apex:outputLink>

                    <apex:outputText value=" | "        
                        rendered="{!$Site.RegistrationEnabled}" />
                    <apex:outputLink value="{!$Page.SiteRegister}"
                        rendered="{!$Site.RegistrationEnabled}">
                        {!$Label.site.new_user_q}
                    </apex:outputLink>

                </apex:panelGroup>
            </apex:panelGrid>
        </apex:outputPanel>
    </apex:form>
</apex:component>
Apex Code for the controller, SiteLoginController:
public class SiteLoginController {
    public String username {get; set;}
    public String password {get; set;}

    public PageReference login() {
        String startUrl = System.currentPageReference().getParameters().get('startURL');
        return Site.login(username, password, startUrl);
    }

       public SiteLoginController () {}

    public static testMethod void testSiteLoginController () {
        // Instantiate a new controller with all parameters in the page
        SiteLoginController controller = new SiteLoginController ();
        controller.username = 'test@salesforce.com';
        controller.password = '123456';

        System.assertEquals(controller.login(),null);                           
    }    
}


bob_buzzardbob_buzzard
What type of user are you attempting to login as?  Sites requires portal/community licenses so a regular user id won't work.
Sonam_SFDCSonam_SFDC
This looks like a login failure as the error suggests..did you check the login history for the site user? What does that show?Also check how you have setup the user to be able to use the Site you've created: https://help.salesforce.com/HTViewHelpDoc?id=siteforce_admin_setup.htm&language=en_US