Quantcast
Channel: Security
Viewing all articles
Browse latest Browse all 4737

Login control shows Invalid credential even after putting the right creadential

$
0
0

Hi All,

Here I am trying to use Login control for login screen. I am putting valid user id and password but it always says invalid credential.

Even I put a break point to find out the fault and in variables it shows valid user id and password.

Why this is happening?

below is my code.

 public bool Authenticate_User(string User_Id, string Password)
    {


        bool boolReturnValue = false;

        String SQLQuery = "Select User_Id, Password from Emp_Details";

        SqlCommand command = new SqlCommand(SQLQuery, EmpCon);
       
        SqlDataReader Dr;
        EmpCon.Open();
        Dr = command.ExecuteReader();
        while (Dr.Read())
        {

            if ((User_Id == Dr["User_Id"].ToString()) & (Password == Dr["Password"].ToString()))
            {
                boolReturnValue = true;
            }
            Dr.Close();
            return boolReturnValue;
        }
        return boolReturnValue;



    }

and in login page

 protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        InventoryService INS = new InventoryService();
        if (INS.Authenticate_User(Login1.UserName, Login1.Password))
        {
            e.Authenticated = true;
            Response.Redirect("Welcome.aspx");
        }
        else
        {
            e.Authenticated = false;
        }
    }

and login control as

<asp:Login ID="Login1" runat="server" OnAuthenticate="Login1_Authenticate" ></asp:Login>


Viewing all articles
Browse latest Browse all 4737

Trending Articles