Monday, May 7, 2007

Login Control in C# ASP.NET 2.0

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="login" %>





Untitled Page








Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284E98" />











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;
using System.Data.SqlClient;

public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
bool Authenticated = false;
Authenticated = SiteLevelCustomAuthenticationMethod(Login1.UserName, Login1.Password);
e.Authenticated = Authenticated;
if (Authenticated == true)
{
// Response.Redirect("Default.aspx");
}
}
private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password)
{
bool boolReturnValue = false;
string strConnection = "server=xxxx;database=xxx_xxxx;uid=xxxx;pwd=xxx;Connect Timeout=60";
SqlConnection Connection = new SqlConnection(strConnection);
string strUserID = UserName;
String strSQL = "select * from UserDetails where UDUSRID=\'" + (strUserID + "\'");
SqlCommand command = new SqlCommand(strSQL, Connection);
SqlDataReader Dr;
Connection.Open();
Dr = command.ExecuteReader();
while (Dr.Read())
{
string UserNameDB = Dr["UDUSRID"].ToString();
string PasswordDB = Dr["UDPASSWD"].ToString();
if ((UserName == UserNameDB.TrimEnd().TrimStart()) & (Password == PasswordDB.TrimEnd().TrimStart()))
{
boolReturnValue = true;
break;
}
}
Dr.Close();
return boolReturnValue;
}
}


www.svdeals.com super value deals

1 comment:

SACHIN CHANDRA!!!!!!!!!!!!!!!! said...

abe kya dala hai yaar kuch nahi samajh me aya