ASP.NET provides a strong login solution for ASP.NET web applications without requiring login control programming. By default, login control integrates with ASP.NETNet membership and form authentication to help automate user authentication for a website. This gives you user-ready user interface to query user names and passwords and provide a login button for login. This subscription validates user credentials against API and contains the original login authentication functionality, such as after successful login, sending you back to the original requested page in the restricted area of the application.
Login Control Displays a user interface for user authentication. The login control includes a username and password and a text box for a check box that allows users to point out whether they want to use the server with their identity ASP.NET subscription and that site Automatically get certified on-the-go.
The login control has properties optimized for customized messages, and links to other pages, where users can change their password or retrieve the forgotten password. Login Control can be used as a standalone control on a main or home page, or you can use it on a dedicated login page. If you use login control with ASP.NET subscription, you do not need to write the code to authenticate. However, if you want to create your own authentication argument, you can handle the login control's authentication event and add custom authentication code.
Demo.Aspx
<asp:Login ID="Login1" runat="server" CssClass="LoginControl"
CreateUserText="Register"
CreateUserUrl="~/Register.aspx"
HelpPageText="Additional Help" HelpPageUrl="~/Help.aspx"
InstructionText="Please enter your user name and password for login.">
<TitleTextStyle BackColor="#6B696B" Font-Bold="True" ForeColor="#FFFFFF" />
</asp:Login>
Demo.Aspx.c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
ViewState["LoginErrors"] = 0;
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
if (YourValidationFunction(Login1.UserName, Login1.Password))
{
// e.Authenticated = true;
Login1.Visible = false;
MessageLabel.Text = "Successfully Logged In";
}
else
{
e.Authenticated = false;
}
}
protected void Login1_LoginError(object sender, EventArgs e)
{
if (ViewState["LoginErrors"] == null)
ViewState["LoginErrors"] = 0;
int ErrorCount = (int)ViewState["LoginErrors"] + 1;
ViewState["LoginErrors"] = ErrorCount;
if ((ErrorCount > 3) && (Login1.PasswordRecoveryUrl != string.Empty))
Response.Redirect(Login1.PasswordRecoveryUrl);
}
private bool YourValidationFunction(string UserName, string Password)
{
bool boolReturnValue = false;
string strConnection = "server=.;database=Vendor;uid=sa;pwd=wintellect;";
SqlConnection sqlConnection = new SqlConnection(strConnection);
String SQLQuery = "SELECT UserName, Password FROM Login";
SqlCommand command = new SqlCommand(SQLQuery, sqlConnection);
SqlDataReader Dr;
sqlConnection.Open();
Dr = command.ExecuteReader();
while (Dr.Read())
{
if ((UserName == Dr["UserName"].ToString()) & (Password == Dr["Password"].ToString()))
{
boolReturnValue = true;
}
Dr.Close();
return boolReturnValue;
}
return boolReturnValue;
}
}
0 comments:
Post a Comment