Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
I am making a login page using this code.
This is only for user but now i want to admin account also so what changes i have to make in this code:

C#
try
            {
                SqlConnection con = new SqlConnection(@"Data Source=LENOVO-41B3F2CE\SQLEXPRESS;Initial Catalog=IMS;Integrated Security=True;Pooling=False");
                string query = "SELECT [user].* FROM [user] where u_name='" + txtusername.Text + "' and pwd='" + txtpassword.Text + "'";
                SqlCommand com = new SqlCommand(query, con);
                con.Open();
                if (com.ExecuteReader().HasRows)
                {
                    //if ((txtusername.Text = "admin") && (txtpassword.Text = "admin"))
                    {
                        Response.Redirect("allinventory.aspx");
                        Label3.Text = "successfully";


                    }
                }
                else
                {
                    Label3.Text = "not successfully";
                    txtusername.Text = "";
                    txtpassword.Text = "";
                }
                con.Close();
            }
            catch (Exception ex)
            {
                Console.Write("" + ex.Message);
            }
Posted
Updated 29-Apr-13 23:33pm
v2

1 solution

Hi,

You can use roles in your database so that you can redirect users according to their roles if the role is 'Admin' then he can access admin section or if he is user then he can access his account as user. You just need three database tables:-

1. Users
2. Roles
3. UsersInRoles

Users table will hold user details.

Roles table will hold your site roles.(e.g. Admin, User)

UsersInRoles will hold mapping of Users and Roles table.

You can create stored procedure to get user details and roles according to given credentials.

Thanks
 
Share this answer
 
Comments
fak_farrukh 30-Apr-13 5:37am    
how to use roles i dont know that
Satyendra Kumar(Analyst Programmer) 30-Apr-13 5:54am    
Create database tables with names Roles and UsersInRoles OR you can use ASP.NET Membership which is good for you as you are new to ASP.NET. For reference please follow : - http://www.codeproject.com/Articles/297597/ASP-NET-Membership

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