0

On the default FBA Login Page, when a user enters wrong username/password an error message gets displayed:

"The server could not sign you in. Make sure your Username and Password are correct, and then try again.".

I want to change this error message to simple text

"Invalid Username and Password".

How can I achieve this?

1

The right way to do this is to create your own custom login page. It needs to be deployed to the layouts folder, outside of the content database.

The simplest and best guide I've found to do this is here:

http://blogs.msdn.com/b/pranab/archive/2010/07/26/how-to-create-custom-login-form-for-sharepoint-2010-form-based-authentication.aspx

The basic code is:

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Page Language="C#" AutoEventWireup="true" Inherits="LdapContosoAuthentication.Layouts.LdapContosoAuthentication.LoginCustmCntrlPage" CodeBehind="LoginCustmCntrlPage.aspx.cs"%>
<html>
<head runat="server">
<title>
Login Page
</title>
<style type="text/css">
    .style1
    {
        width: 100%;
    }
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="style1">
    <tr>
        <td>
            UserID</td>
        <td>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td>
            Password</td>
        <td>
            <asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td>
            <asp:Label ID="Label1" runat="server"></asp:Label>
        </td>
        <td>
            <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" />
        </td>
    </tr>
</table>
</div>
</form>
</body>
</html>

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.IdentityModel;

namespace LdapContosoAuthentication.Layouts.LdapContosoAuthentication
{
    public partial class LoginCustmCntrlPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            bool status = SPClaimsUtility.AuthenticateFormsUser(Context.Request.UrlReferrer, TextBox1.Text, TextBox2.Text);
            if (!status)
            {
                Label1.Text = "Wrong Userid or Password";
            }
            else
            {
                if (Context.Request.QueryString.Keys.Count > 1)
                {
                    Response.Redirect(Context.Request.QueryString["Source"].ToString());
                }
                else
                    Response.Redirect(Context.Request.QueryString["ReturnUrl"].ToString());
            }
        }
    }
}

I'd recommend that you have your styles in the aspx page, as you won't be able to access the masterpage and styles if not logged in.

You can then change the login page in the Central Admin settings for the FBA:

Application Management > Web Applications > Click on your site > Authentication Providers > Click on Default (if that's what you have) > Sign in Page URL

If it's SP2013, the path will be /_layouts/15/{VSProjectName}/{PageName}.aspx. The old page may be cached for some time though.

  • Thanks @joanne for your detailed answer. I am actually using a hybrid login page. I copied default.aspx to my mapped layouts folder and started changing it. However, I am still using SharePoint default login control. That is why I am getting the default SharePoint Login Error Message. It is coming from FailureText="<%$Resources:wss,login_pageFailureText%>". I changed the text to FailureText="Invalid Username and Password" and it has solved my issue :) – Sudhakar Sep 1 '14 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.