locked
Login failture RRS feed

  • Question

  • User1113074264 posted

    Hi,

    I'm having problem with my userlogin control.it is connected to database .i don't know what is the error.i want to display the name of user after he has logged in.the login display changed into logout.how to include these into my login control ?

     protected void Login1_Authenticate1(object sender, AuthenticateEventArgs e)
            {
                string userName = Login1.UserName;  
                string password = Login1.Password;  
       
          bool result = UserLogin(userName, password);  
          if ((result))  
          {  
              e.Authenticated = true;  
          }  
          else  
          {  
              e.Authenticated = false;  
          }  
            }
    
            private bool UserLogin(string userName, string password)
            {
    
                // read the coonection string from web.config 
                string conString = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString;
    
                using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(conString))
                {
                    //' declare the command that will be used to execute the select statement 
                    SqlCommand com = new SqlCommand("SELECT CustomerId FROM Customer WHERE CustomerId = @CustomerId AND Password = @Password", con);
    
                    // set the username and password parameters
                    com.Parameters.Add("@CustomerId", SqlDbType.VarChar).Value = userName;
                    com.Parameters.Add("@Password", SqlDbType.VarChar).Value = password;
    
                    con.Open();
                    //' execute the select statment 
                    string result = Convert.ToString(com.ExecuteScalar());
                    //' check the result 
                    if (string.IsNullOrEmpty(result))
                    {
                        //invalid user/password , return flase 
                        return false;
                    }
                    else
                    {
                        // valid login
                        return true;
                    }
                }
            }


    Wednesday, December 22, 2010 12:15 PM

Answers

  • User-1199946673 posted

    When using e memberhip provider, all you need to do is configure the provider in your web.config and the login control works out of the box, without using any code behind

     http://www.asp.net/web-forms/security

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 24, 2010 6:05 AM

All replies

  • User-525407762 posted

    I could not understand your question, can you please explain it further.

    Thursday, December 23, 2010 6:04 AM
  • User1113074264 posted

    hi.im using asp login control for my login page.i have codeed above. i don't know what is the error. is there error conncting to database ?

    then i want to hide the login page after user has logged in and display the logout link.how do i do ?


    Thursday, December 23, 2010 10:52 AM
  • User-1199946673 posted

    i don't know what is the error
     

    How would we know if you don't tell us the error you're getting and/or the problem you've?

    then i want to hide the login page after user has logged in and display the logout link.how do i do ?

    Use a loginview control. put the login control in the anonymous template and the logout link in the loggedin template....

    Thursday, December 23, 2010 4:39 PM
  • User1113074264 posted

    hi hans_v,

    sorry for that.there was no syntax error.when i tried to login using correct username and passoword.it shows me the login failure

    message as "Your login failture was unsuccessful" is there problem with database connection or passing the value to query?

    Thursday, December 23, 2010 11:56 PM
  • User-1199946673 posted

    When using e memberhip provider, all you need to do is configure the provider in your web.config and the login control works out of the box, without using any code behind

     http://www.asp.net/web-forms/security

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 24, 2010 6:05 AM