登录错误消息未显示 [英] Login Error Message not displaying

查看:77
本文介绍了登录错误消息未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作正常的登录屏幕。用户输入用户名和密码时出现问题。问题是当用户输入正确的用户名但密码不正确时,错误按摩不会显示。如果用户输入错误的用户名和密码,它可以正常工作。有人可以帮我吗?



I have a login screen that works fine. I have an issue when the user enters the username and password. The issue is when the user enters the correct username but incorrect password the error massage does not display. It works fine if the user enters the incorrect username and password. Can someone help me with this?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
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)
    {
        if (IsPostBack)
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
            con.Open();

            string cmdStr = "select count (*) from Table1 where EmailAddress='" + TextBoxEA.Text + "'";
            SqlCommand userExist = new SqlCommand(cmdStr, con);

            SqlCommand insertcmd = new SqlCommand("insert into Table1", con);
            SqlDataAdapter dap = new SqlDataAdapter(insertcmd);
            int temp = Convert.ToInt32(userExist.ExecuteScalar().ToString());
            con.Close();

            if (temp == 0)
                lblMessage.Text = "Invalid User Name and Password";
            
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

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



        if (true)
        {
            SqlCommand level = new SqlCommand("select accessLevel, Password, INST_ID from Table1 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());
                int inst_id = Convert.ToInt32(dr1[2].ToString());
                Session["inst_id"] = inst_id;
                    
                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");
                }
                else if (returnedLevel == 11)
                {
                    Response.Redirect("FormAPublicL.aspx");
                }
                else if (returnedLevel == 21)
                {
                    Response.Redirect("FormCPrivateNonL.aspx");
                }
                else if (returnedLevel == 31)
                {
                    Response.Redirect("FormDPrivateForL.aspx");
                }
                else if (returnedLevel == 0)
                {
                    lblMessage.Text = "Invalid UserName and Password";
                }
            }
        }
    }
}

推荐答案

I猜你需要在页面加载事件中更改sql查询过滤条件,你还需要包含和条件密码...截至目前我可以看到你只用用户名过滤表..所以如果只给出用户名错误然后它将显示错误消息...如果用户名正确,则不显示任何消息。
I guess you neeed to change the sql query filter condition in page load event, U need to include and condition for password also... As of now I can see that u are filtering table only with username.. so if username is given wrong only then it will show the error message... If username is correct no message is displayed.


这篇关于登录错误消息未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆