Quantcast
Channel: Security
Viewing all articles
Browse latest Browse all 4737

Security authorization

$
0
0

I am writing a code for my website to have a security login so that when you login if you are admin or super admin the appropriate options would become available. However I am getting an error (picture of it will be below). I was wondering if you can look at my error and code and tell me if I did something wrong or where I can improve as I only just started learning Sessions, so I could have made a mistake somewhere.

----------part 1----------
DAL dal = new DAL("Data Source=localhost;Initial Catalog=dbMagazine;Integrated Security=SSPI");

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            dal.AddParam("@Username", txtUsername.Text);
            dal.AddParam("@Passwords", txtPassword.Text);
            DataSet ds = dal.ExecuteProcedure("spLogin");
            if(ds.Tables[0].Rows.Count > 0)
            {
                txtUsername.Text = ds.Tables[0].Rows[0]["Username"].ToString();
                txtPassword.Text = ds.Tables[0].Rows[0]["Passwords"].ToString();
                Response.Write("Login Successful.");

                Session["LoginID"] = ds.Tables[0].Rows[0]["LoginID"].ToString(); ;
                Session["SecurityLVL"] = ds.Tables[0].Rows[0]["SecurityLVL"].ToString(); ;
                Session["Username"] = ds.Tables[0].Rows[0]["Username"].ToString();
                Session["Passwords"] = ds.Tables[0].Rows[0]["Passwords"].ToString();
                Response.Redirect("HomePage.aspx");
            }


----------part 2----------
 DAL dal = new DAL("Data Source=localhost;Initial Catalog=dbMagazine;Integrated Security=SSPI");

        protected void Page_Load(object sender, EventArgs e)
        {
            if ((int)Session["SecurityLVL"] == 1)
            {
                Response.Write("I am watching YOU :|");
            }
            else if ((int)Session["SecurityLVL"] == 2)
            {
                btnAdd.Visible = true;
                FUpload.Visible = true;
                DDLoad.Visible = true;
                Image1.Visible = true;
                Response.Write("Editor has final say on everything remember.");
            }

            else if ((int)Session["SecurityLVL"] == 3)
            {
                btnAdd.Visible = true;
                FUpload.Visible = true;
                DDLoad.Visible = true;
                Image1.Visible = true;
                btnEdit.Visible = true;
                btnDelete.Visible = true;
                btnArticle.Visible = true;
                txtInput.Visible = true;
                Response.Write("Welcome back Boss");
            }

            else
            {
                Response.Write("ACCESS DENIED");
            }

One more note that those 2 codes are from different pages.

Here is the error

http://s952.photobucket.com/user/athrun5/media/Untitled.jpg.html


Viewing all articles
Browse latest Browse all 4737

Trending Articles