Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Plain Text by registered user JaneLigones ( 13 years ago )
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;
using System.Data;

public partial class Home : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(Helper.GetConnectionString());
    Helper help = new Helper();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["userid"] != null)
            pnlLog.Visible = false;
        else
        {
            Session["page"] = "login";
            pnlLog.Visible = true;

        }
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        if (ddlUser.SelectedItem.Value == "Customer")
        {
            LoginCustomer();
        }
        else if (ddlUser.SelectedItem.Value == "Employee")
        {
            LoginEmployee();
        }
    }

    void LoginCustomer()
    {
        //string strDecrypt = help.Decrypt(txtPassword.Text);

        con.Open();
        SqlCommand com = new SqlCommand();
        com.Connection = con;
        com.CommandText = "SELECT * FROM Customers WHERE Username=@Username AND " +
            "IsApproved='1'";
        com.Parameters.Add("@Username", SqlDbType.NVarChar).Value = txtUsername.Text;
        //com.Parameters.Add("@Password", SqlDbType.NVarChar).Value = strDecrypt;
        SqlDataReader data = com.ExecuteReader();

        if (data.HasRows)
        {
            lblError.Visible = false;
            while (data.Read())
            {
                if (txtPassword.Text == Helper.Decrypt(data["Password"].ToString(), true))
                //if (txtPassword.Text == (data["Password"].ToString()))
                {
                    Session["userid"] = data["CustID"].ToString();
                    Response.Redirect("~/Customer/MyAccount.aspx");
                }
                else
                    lblError.Visible = true;

            }
            con.Close();

            //if (Request.QueryString["returnUrl"] != null)
            //    Response.Redirect(Request.QueryString["returnUrl"].ToString());
            //else
            //    Response.Redirect("MyProfile.aspx");
        }
        else
        {
            lblError.Visible = true;
        }
        con.Close();
    }

    void LoginEmployee()
    {
        //string strDecrypt = help.Decrypt(txtPassword.Text);

        con.Open();
        SqlCommand com = new SqlCommand();
        com.Connection = con;
        com.CommandText = "SELECT EmpID FROM Employees WHERE Username=@Username AND " +
            "IsLockedOut='False'";
        com.Parameters.Add("@Username", SqlDbType.NVarChar).Value = txtUsername.Text;
        //com.Parameters.Add("@Password", SqlDbType.NVarChar).Value = strDecrypt;
        SqlDataReader data = com.ExecuteReader();



        if (data.HasRows)
        {
            lblError.Visible = false;
            while (data.Read())
            {
                if (txtPassword.Text == Helper.Decrypt(data["Password"].ToString(), true))
                {
                    Session["userid"] = data["EmpID"].ToString();
                    Response.Redirect("MyProfile.aspx");
                }
                else
                    lblError.Visible = true;
            }
            con.Close();

            //if (Request.QueryString["returnUrl"] != null)
            //    Response.Redirect(Request.QueryString["returnUrl"].ToString());
            // else
            //    Response.Redirect("MyProfile.aspx");

        }
        else
        {
            lblError.Visible = true;
        }
        con.Close();
    }


    protected void ddlUser_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlUser.SelectedItem.Value == "Select here..")
        {
            pnlLogin.Visible = false;

        }

        else
        {
            pnlLogin.Visible = true;
        }
            
    }

    void ReturnUrl(int Return)
    {

    }
}

 

Revise this Paste

Your Name: Code Language: