Click here to Skip to main content
16,018,264 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I had a Login.aspx page. I want to replace the original error message so that user can know what they had wrongly input into the Login Control.

However, after adding all the related codes and checking through my Login.aspx.cs file, and test run it, the default message keep appearing.
"Your login attempt was not successful. Please try again"


Seems that the code that I wrote didn't executed. And I had not know what was wrong at it.

Here is my Login.aspx.cs code:
protected void Login1_LoginError(object sender, System.EventArgs e)
   {

           System.Web.UI.WebControls.Login Login1 = (System.Web.UI.WebControls.Login)LoginView1.FindControl("Login1");
           TextBox UserName = (TextBox)Login1.FindControl("UserName");
           Literal FailureText = (Literal)Login1.FindControl("FailureText");

       //There was a problem logging in the user
       //See if this user exists in the database

       MembershipUser userInfo = Membership.GetUser(UserName.Text);
       if (userInfo == null)
       {
           //The user entered an invalid username...

           FailureText.Text = "There is no user in the database with the username " + UserName.Text;
       }
       else
       {
           //See if the user is locked out or not approved
           if (!userInfo.IsApproved)
           {
               FailureText.Text = "When you created your account you were sent an email with steps to verify your account. You must follow these steps before you can log into the site.";
           }
           else if (userInfo.IsLockedOut)
           {
               FailureText.Text = "Your account has been locked out because of a maximum number of incorrect login attempts. You will NOT be able to login until you contact a site administrator and have your account unlocked.";
           }
           else
           {
               //The password was incorrect
               FailureText.Text = "Invalid Password. Please try again." ;
           }
       }
   }


Can anyone help me suggestions what was wrong with the code?
Thanks!
Posted
Comments
Sandeep Mewara 25-Jun-12 11:52am    
I don't see "Your login attempt was not successful. Please try again" in your code anywhere.
mathidioticz 25-Jun-12 11:58am    
The "Your login attempt was not successful. Please try again" was default. It came together along when I drag and drop into my website.
OriginalGriff 25-Jun-12 14:51pm    
Just as an aside, it is a bad idea to have separate error messages for "invalid user" and "invalid password". If you have only the one message, it makes it a little harder for hackers to find a valid username / password combo. With separate messages, the first time they get "invalid password" they know they have a valid user id.

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