Click here to Skip to main content
15,921,660 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a login table in which i have four columns id, username, password and SuperUser. when i login i want to show specific pages to normal user and whole pages to superuser. what i tried is:

protected void LoginButton_Click(object sender, EventArgs e)
        {
            SqlConnection con=new SqlConnection(@"Data Source=ashish-pc\;Initial Catalog=HMS;Integrated Security=True");
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from Login where UserName=@UserName and Password=@Password", con);
            cmd.Parameters.AddWithValue("@UserName", UserName.Text.Trim() );
            cmd.Parameters.AddWithValue("@Password", Password.Text.Trim());
            cmd.Parameters.Add("IsSuperUser");

            
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;
            DataSet dt = new DataSet();
            
            da.Fill(dt);
            if (dt.Tables[0].Rows.Count>0)
            {
                

                
                Session["UserName"] = UserName.Text;
                Session.Timeout = 1;

                //Session["Login"] =     
                Response.Redirect("/Home.aspx");
                
            }
            else 
            {
                 Response.Write("Invalid username and password");
            }
            con.Close();
        }


please help
Posted
Comments
[no name] 9-Apr-14 8:59am    
You have a parameter "IsSuperUser" that you do not even use in your query.... why?

1 solution

Ass UserType Column in you data table with datataype varchar or char.
Save 'S' for SuperUser
Save 'N' for Normal User

Now when log in add check like
C#
if(UserType == 'S')
{
//This i ssuper user
}
else
{
//this is normal user
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900