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

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

I used this tutorial from 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="{!$}" for="username" />
                <apex:inputText id="username" value="{!username}" />
                <apex:outputLabel value="{!$}" for="password" />
                <apex:inputSecret id="password" value="{!password}" />

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

                    <apex:outputLink value="{!$Page.ForgotPassword}">

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

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 = '';
        controller.password = '123456';


What type of user are you attempting to login as?  Sites requires portal/community licenses so a regular user id won't work.
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: