Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

Login Not Working

$
0
0

I am getting my User login credentials from a database table.

The User login works fine when it is tested from my pc but when it is moved to a server I get a Login Failed message, but the login that fails is the ServerName and not the Username as it should be.

Anyone know why this could be ?

Code below:

SqlDataAdapter daUserName, daStaffNo;
        String username = "domain\\", sqlUserNames, sqlDepartmentUsers , strStaffNo;
        static String password = "staff";
        DataSet dsUsers = new DataSet();
        DataRow drUsers;
        int staffNo;
        SqlCommand cmdGetStaffNo;
        Boolean filled = true;

        protected void Page_Load(object sender, EventArgs e)
        {
            sqlUserNames = @"Select StaffNo from Staff where @username = NTUserName";
            sqlDepartmentUsers = @"Select StaffNo from Department";

            lblErrorPassword.Visible = false;
            lblErrorName.Visible = false;
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (filled)
            {
                dsUsers.Tables.Clear();
            }

            username += txtUserName.Text;

            cmdGetStaffNo = new SqlCommand(sqlUserNames, conn);
            cmdGetStaffNo.Parameters.AddWithValue("@username", username);

            daUserName = new SqlDataAdapter(cmdGetStaffNo);
            daUserName.FillSchema(dsUsers, SchemaType.Source);
            daUserName.Fill(dsUsers, "UserNames");

            if (dsUsers.Tables["UserNames"].Rows.Count == 0)
            {
                lblErrorName.Visible = true;
            }
            else
            {
                drUsers = dsUsers.Tables["UserNames"].Rows[0];
                strStaffNo = drUsers["StaffNo"].ToString();
                staffNo = int.Parse(strStaffNo);
            }

            daStaffNo = new SqlDataAdapter(sqlDepartmentUsers, conn);
            daStaffNo.FillSchema(dsUsers, SchemaType.Source);
            daStaffNo.Fill(dsUsers, "StaffNo");

            Response.BufferOutput = true;

            foreach (DataRow dr in dsUsers.Tables["StaffNo"].Rows)
            {
                if (staffNo == int.Parse(dr["StaffNo"].ToString()) && txtPassword.Text == password)
                    Response.Redirect("Main.aspx?field1= " + staffNo);

                else if (staffNo == int.Parse(dr["StaffNo"].ToString()) && txtPassword.Text != password)
                {
                    lblErrorPassword.Visible = true;
                    lblErrorName.Visible = false;
                    break;
                }

                else if (staffNo != int.Parse(dr["StaffNo"].ToString()) && txtPassword.Text == password)
                {
                    lblErrorName.Visible = true;
                    lblErrorPassword.Visible = false;
                }
                else if (staffNo != int.Parse(dr["StaffNo"].ToString()) && txtPassword.Text != password)
                {
                    lblErrorName.Visible = true;
                    lblErrorPassword.Visible = true;
                }
            }

Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>