in C# Asp.net 2.0,3.5
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.OleDb;
public partial class signon : System.Web.UI.Page
{
string CaseIDClient;
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)
{
OleDbConnection conDatabase = null;
OleDbDataReader Dr = null;
bool boolReturnValue = false;
string strUserID = UserName;
conDatabase = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\\sites\\Single15\\visli\\database\\H4rDB.mdb");
conDatabase.Open();
string strSQL = "select * from USERS where USERID=\'" +
(strUserID + "\'");
OleDbCommand cmdDatabase = new OleDbCommand(strSQL, conDatabase);
Dr = cmdDatabase.ExecuteReader();
while (Dr.Read())
{
string UserNameDB = Dr["USERID"].ToString();
string PasswordDB = Dr["PASSWORD"].ToString();
string userbranchDB = Dr["USERBRANCH"].ToString();
string userRoleDB = Dr["ROLE"].ToString();
if ((UserName == UserNameDB.TrimEnd().TrimStart()) &
(Password == PasswordDB.TrimEnd().TrimStart()))
{
Session["loginm"] = strUserID;
Session["userRole"] = userRoleDB;
Session["userBranch"] = userbranchDB;
Session["BRANCH"] = userbranchDB;
Session["CaseIDClient"] = Dr["CASENO"];
boolReturnValue = true;
break;
}
}
conDatabase.Close();
Dr.Close();
return boolReturnValue;
}
}
No comments:
Post a Comment