How to implement forms authentication in asp.net c# using mssql?
<p>I have Login.aspx page </p>

<pre><code>&lt;asp:Login ID="Login1" style=" margin-top:150px;" runat="server"&gt;
    &lt;LayoutTemplate&gt;
        &lt;table cellpadding="1" cellspacing="0" style=" background-color:#1b4c6c; color:White; font-family:Calibri; border-collapse:collapse;"&gt;
            &lt;tr&gt;
                &lt;td&gt;
                    &lt;table cellpadding="0"&gt;
                        &lt;tr&gt;
                            &lt;td align="center" colspan="2"&gt;
                                Log In&lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                            &lt;td align="right"&gt;
                                &lt;asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName"&gt;User Name:&lt;/asp:Label&gt;
                            &lt;/td&gt;
                            &lt;td&gt;
                                &lt;asp:TextBox ID="UserName" runat="server" style=" border-radius:3px; padding-left:3px;"&gt;&lt;/asp:TextBox&gt;
                                &lt;asp:RequiredFieldValidator ID="UserNameRequired" runat="server" 
                                    ControlToValidate="UserName" ErrorMessage="User Name is required." 
                                    ToolTip="User Name is required." ValidationGroup="Login1"&gt;*&lt;/asp:RequiredFieldValidator&gt;
                            &lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                            &lt;td align="right"&gt;
                                &lt;asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password"&gt;Password:&lt;/asp:Label&gt;
                            &lt;/td&gt;
                            &lt;td&gt;
                                &lt;asp:TextBox ID="Password" runat="server" style=" border-radius:3px; padding-left:3px;" TextMode="Password"&gt;&lt;/asp:TextBox&gt;
                                &lt;asp:RequiredFieldValidator ID="PasswordRequired" runat="server" 
                                    ControlToValidate="Password" ErrorMessage="Password is required." 
                                    ToolTip="Password is required." ValidationGroup="Login1"&gt;*&lt;/asp:RequiredFieldValidator&gt;
                            &lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                            &lt;td colspan="2"&gt;
                                &lt;asp:CheckBox ID="RememberMe" runat="server" Text="Remember me next time." /&gt;
                            &lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                            &lt;td align="center" colspan="2" style="color:Red;"&gt;
                                &lt;asp:Literal ID="FailureText" runat="server" EnableViewState="False"&gt;&lt;/asp:Literal&gt;
                            &lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;tr&gt;
                            &lt;td align="right" colspan="2"&gt;
                                &lt;asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" 
                                    ValidationGroup="Login1" /&gt;
                            &lt;/td&gt;
                        &lt;/tr&gt;
                    &lt;/table&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
        &lt;/table&gt;
    &lt;/LayoutTemplate&gt;
&lt;/asp:Login&gt;
</code></pre>

<p>and in Login.aspx.cs page i do the following</p>

<pre><code>using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if((Session["portal"]!=null)&amp;&amp; (Convert.ToBoolean(Session["portal"])==true))
        {
            if (User.Identity.IsAuthenticated)
            {
                Response.Redirect("Default.aspx");
            }
        }
    }


protected static Boolean Authentication(string username, string password)
{
    string sqlstring;
             sqlstring = "Select username, password from tbluser where username='" + username + "' and password ='" + password + "'";

             // create a connection with sqldatabase 
             System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(" Data Source=./SQLEXPRESS;Initial Catalog=Database;Connect Timeout=10;TrustServerCertificate=True "); 

            // create a sql command which will user connection string and your select statement string
            System.Data.SqlClient.SqlCommand comm = new System.Data.SqlClient.SqlCommand(sqlstring,con);

            // create a sqldatabase reader which will execute the above command to get the values from sqldatabase
            System.Data.SqlClient.SqlDataReader reader;

            // open a connection with sqldatabase
            con.Open();

            // execute sql command and store a return values in reade
            reader = comm.ExecuteReader();

            // check if reader hase any value then return true otherwise return false
            if (reader.Read())
               return true;
            else
               return false;
       }

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{

    Boolean blnresult;
    blnresult = false;
    blnresult = Authentication( Login1.UserName, Login1.Password);
    if (blnresult = true)
    {
        e.Authenticated = true;
        Session["portal"] = true;
    }
    else
        e.Authenticated = false;
}
</code></pre>

<p>}</p>

<p>I have table with columns username &amp; password with values admin &amp; admin respectively.
But Login control is giving error message <strong>Your login attempt was not successful. Please try again.</strong></p>

<p>Can anyone tell that what may be the problem is??</p>
