<pre>using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; public partial class Login : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString); protected void Page_Load(object sender, EventArgs e) { try { if (!Page.IsPostBack) { if (Request.QueryString.Count > 0) { string UserID = Request.QueryString["UserID"]; Session["UserID"] = UserID; Response.Redirect("Default.aspx",false); } } } catch (Exception ex) { Session["Error"] = ex.ToString(); Response.Redirect("Error.aspx"); } } protected void btnLogin_Click(object sender, EventArgs e) { try { if (CheckUsername()) { if (CheckPassword()) { RedirectPage(); } else { lblError.Text = "Your login attempt has failed. <BR>Please try again!"; } } else { lblError.Text = "Your login attempt has failed. <BR>The username or password may be incorrect"; } } catch (Exception ex) { Session["Error"] = ex.ToString(); Response.Redirect("Error.aspx"); } } public bool CheckUsername() { string Query = "select * from users where IsActive='True' and Email='" + txtUserName.Text + "'"; DataTable dt = GetData(Query); if (dt.Rows.Count > 0) return true; else return false; } public bool CheckPassword() { string Query = "select * from users where IsActive='True' and Email='" + txtUserName.Text + "' and Password='"+txtPassword.Text+"'"; DataTable dt = GetData(Query); if (dt.Rows.Count > 0) return true; else return false; } public DataTable GetData(string Query) { SqlCommand cmd = new SqlCommand(Query, con); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); return dt; } public void RedirectPage() { string Query = "select top(1) * from users where IsActive='True' and Email='" + txtUserName.Text + "' and Password='" + txtPassword.Text + "'"; DataTable dt = GetData(Query); if (dt.Rows.Count == 1) { Session["UserID"] = dt.Rows[0]["UserID"].ToString(); Response.Redirect("Home.aspx", false); } else { lblError.Text = "You don't have permission to view this Site!"; Session["UserID"] = ""; } /*if (dt.Rows.Count == 1) { if (Convert.ToBoolean(dt.Rows[0]["Products"]) == true && Convert.ToBoolean(dt.Rows[0]["Users"]) == true) { Session["UserID"] = dt.Rows[0]["UserID"].ToString(); Response.Redirect("Default.aspx", false); } else if (Convert.ToBoolean(dt.Rows[0]["Products"]) == true && Convert.ToBoolean(dt.Rows[0]["Users"]) == false) { Session["UserID"] = dt.Rows[0]["UserID"].ToString(); Response.Redirect("Default.aspx", false); } else if (Convert.ToBoolean(dt.Rows[0]["Products"]) == false && Convert.ToBoolean(dt.Rows[0]["Users"]) == true) { Session["UserID"] = dt.Rows[0]["UserID"].ToString(); Response.Redirect("Users.aspx", false); } else { Session["UserID"] = ""; Response.Redirect("Login.aspx", false); } } else { lblError.Text = "You don't have permission to view this Site!"; Session["UserID"] = ""; }*/ } }
Response.Redirect("Home.aspx", true);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)