Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# database Authentication , +
I have a login form in which user have to enter credential i.e. username and password.In my code i check that user whether it is an authorized user or not now i also want to check what is the access level of that user according to its role
 
here is my login page code:
 
protected void btnSubmit_Click(object sender, EventArgs e)
{
    String queryread = @"Select * from Login where UserName = '" + tbUserName.Text.ToLower() + "' and Password='"+ tbPassword.Text.ToLower() +"'";
    SqlConnection con = new SqlConnection();
    SqlDataReader read;
    con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["BartConnectionString"].ConnectionString;
    SqlCommand readdata = new SqlCommand(queryread, con);
    try
    {
        con.Open();
        read = readdata.ExecuteReader();
        Boolean flag = false;
        while (read.Read())
        {
            String UserName = read["UserName"].ToString().ToLower();
            String password = read["Password"].ToString();
            if (tbUserName.Text.ToLower() == UserName)
            {
                if (tbPassword.Text.Trim() == password)
                {
                        Session["UserID"] = UserName.ToString();
                        flag = true;   
                }
            }
        }
        if (flag)
        {
 
            Response.Redirect("~/Supervisor/Form.aspx",false);
        }
        else
        {
            Response.Redirect("~/Error.aspx",false);
        }
    }
    catch (Exception ex2)
        {
            Response.Write("Error");
        }
    finally
        {
        if (con.State == System.Data.ConnectionState.Open)
            con.Close();
        }
    }
 
in the upper code i check authorized user from database and then redirect user accordingly to particular folder and error page. now i want to check if that user is admin it will redirect to admin page in admin folder, if it is manager it will redirect to manager page in manager folder and so on.
 
for this i need to know.
 
Database schema for it
What is the code used in web.config file to provide access according to roles.
 
and what if i need to make some changes then let me know guys.
 
Thanks in Advance
Posted 17-May-13 0:00am

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

  Print Answers RSS
0 OriginalGriff 290
1 Jochen Arndt 150
2 Kornfeld Eliyahu Peter 149
3 PIEBALDconsult 110
4 Richard MacCutchan 105
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 17 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100