Click here to Skip to main content
15,913,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a login that I have been working on. The login works but I want to change somethings. I want to authenticate between users of the program. Every user has a username and password. They also have an ID. I want to authenticate with the ID to show a page just for that user. Right now it works with the levels. I gave each test user a different level. How can I use the ID to give them the same access but show them a page just for them? And how can that page only show their profile and no one else? Here is the code I have:

C#
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.Configuration;
using System.Data;


public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }

    protected void Button1_Click(object sender, EventArgs e)
    {

        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();

        if (true)
        {
            SqlCommand level = new SqlCommand("select AccessLevel, Password from TableSecurity where EmailAddress = @EmailAddress AND Password = @Password", con);
            level.Parameters.Add(new SqlParameter("EmailAddress", TextBoxEA.Text));
            level.Parameters.Add(new SqlParameter("Password", TextBoxPW.Text));

            SqlDataReader reader = level.ExecuteReader();
            DataTable dt1 = new DataTable();
            dt1.Load(reader);

            foreach (DataRow dr1 in dt1.Rows)
            {
                int returnedLevel = Convert.ToInt32(dr1[0].ToString());

                if (returnedLevel == 1)
                {
                    Response.Redirect("FormAPublic.aspx");
                }
                else if (returnedLevel == 2)
                {
                    Response.Redirect("FormCPrivateNon.aspx");
                }
                else if (returnedLevel == 3)
                {
                    Response.Redirect("FormDPrivateFor.aspx");
                }
                else if (returnedLevel == 7)
                {
                    Response.Redirect("CEOPage.aspx");
                }
                else if (returnedLevel == 8)
                {
                    Response.Redirect("DBPage.aspx");
                }
            }
        }
        con.Close();
    }
    
}
Posted

1 solution

You will need to dynamically create that profile page from the user's profile table. That is you have the layout of the page and where you want to display what profile information. So when user logs in, go to the User Profile table, get the details and put them in the places already provided for.

I hope this helps.
 
Share this answer
 
Comments
Computer Wiz99 27-Sep-13 10:47am    
Member 2838283, This does help a little but I will have to create a profile page from a profile table. Where is the profile table location and where do I create the table if I need to?
Jide X 29-Sep-13 15:01pm    
The profile table is totally up to you. You have decided to have a User table that has ID. You can also decide to have other fields (in the same table) for the user's profile. When you know the ID of the logged in user, you can then read other fields of interest to construct the profile page.
Computer Wiz99 1-Oct-13 9:06am    
Sorry for the late response. I do have a profile table. I have two of them for two different groups. One is called CEO and the other is IALO. I do have ID, Last Name, First Name and other things in them. When the user logs into the website, How do I get it to just show only the things for that user? How can I get the user profile to just load that user when they login?

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