Click here to Skip to main content
15,909,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need help with my log in page. I have a login page that every time I enter a username and password it goes black. The textboxes information are cleared out. What did I do wrong. What I am trying to do is to have one member with a level number to be redirected to one welcome page and the other user with another level number be directed to his/her welcome page. Please help me.
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["PassConnectionString"].ConnectionString);
        con.Open();


            if (true)
            {
                string cmdStr3 = "select Password, accessLevel from TableSecurity where EmailAddress= '" + TextBoxEA.Text + "'";
                SqlCommand level = new SqlCommand(cmdStr3, con);
                
                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("~/Secure.aspx");
                }
 
                else if (returnedLevel == 2)
                {
                    Response.Redirect("~/WelcomeIALO.aspx");
                }
            }
        }
        con.Close();
        }
    }
Posted
Updated 2-May-13 8:40am
v3
Comments
Richard C Bishop 2-May-13 10:04am    
Ok, can you post the structure and records of your new table. I am going to duplicate all of this in my application.
Computer Wiz99 2-May-13 10:25am    
Ok. There three Tables. TableCEO, TableIALO, TableSecurity.

TableCEO:

INST_ID varchar(50) Unchecked
LastName varchar(50) Unchecked
FirstName varchar(50) Unchecked
MiddleName varchar(50) Checked
Prefix varchar(4) Unchecked
Suffix varchar(50) Checked
Salutation varchar(50) Checked
Title varchar(50) Unchecked
Address1 varchar(50) Unchecked
Address2 varchar(50) Unchecked
City varchar(50) Unchecked
State varchar(50) Unchecked
Zip numeric(18, 0) Unchecked
Country varchar(50) Checked
Phone numeric(18, 0) Unchecked
Fax numeric(18, 0) Unchecked
EmailAddress varchar(50) Unchecked
INST_CEO_I numeric(18, 0) Unchecked
Cell numeric(18, 0) Unchecked
LastUpdate datetime Checked
Level numeric(18, 0) Checked

TableIALO:
INST_ID varchar(50) Unchecked
LastName varchar(50) Unchecked
FirstName varchar(50) Unchecked
MiddleName varchar(50) Checked
Prefix varchar(4) Unchecked
Suffix varchar(50) Checked
Salutation varchar(50) Checked
Title varchar(50) Unchecked
Address1 varchar(50) Unchecked
Address2 varchar(50) Unchecked
City varchar(50) Unchecked
State varchar(50) Unchecked
Zip numeric(18, 0) Unchecked
Country varchar(50) Checked
Phone numeric(18, 0) Unchecked
Fax numeric(18, 0) Unchecked
EmailAddress varchar(50) Unchecked
LastUpdate datetime Checked
Level numeric(18, 0) Checked

TableSecurity:

INST_ID varchar(50) Checked
EmailAddress varchar(50) Unchecked
Password varchar(50) Unchecked
Level numeric(18, 0) Checked

The TableSecurity stores the username and password. The username is the emailaddress. The password is what the user comes up with and then stored in the TableSecurity. The program reads from TableCEO and TableIALO to make sure the user exist and can make a password. After the user makes the password and it is stored in the TableSecurity the program reads from that table in order to login the user.
Richard C Bishop 2-May-13 10:44am    
Ok, I got it all to work. Can you list the data in the the TableSecurity table. I want to see what it looks like.
Computer Wiz99 2-May-13 11:00am    
Ok. Here it is. This is what is in the TableSecurity.

INST_ID EmailAddress Password Level
10880 milholland@acu.edu iloveme 1
10880 schubert@acu.edu password 2
Richard C Bishop 2-May-13 11:03am    
Ok, do this. Add "access" to the column name Level. "level" is a keyword in SQL. Next, see my solution below. It is only the redirecting part. We can tackle another issue next if you have it.

1 solution

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 _Default : System.Web.UI.Page
{
    protected void Button1_Click1(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["PassConnectionString"].ConnectionString);
        con.Open();
 
        if (true)
        {
            SqlCommand level = new SqlCommand("select accessLevel, Password from TableSecurity where EmailAddress = @Email AND Password = @password", con);
            level.Parameters.Add(new SqlParameter("Email", 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("~/Default2.aspx");
                }
 
                else if (returnedLevel == 2)
                {
                    Response.Redirect("~/Default2.aspx");
                }
            }
        }
        con.Close();
    }
}
 
Share this answer
 
v5

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