Click here to Skip to main content
16,020,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
M using asp login control . here is my code
C#
<asp:Login ID="loginDetails"
                                UserNameRequiredErrorMessage="Enter user name" runat="server"
                                PasswordRecoveryText="Forgot Password?"
                                PasswordRecoveryUrl="~/ForgotPassword.aspx" FailureText="The user name or password is incorrect."
                                OnAuthenticate="login_Authenticate" ForeColor="Black" BackColor="#F7F7DE" BorderColor="#CCCC99"
                                BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana"
                                Font-Size="10pt" DisplayRememberMe="False" RememberMeText="">
                                <TitleTextStyle BackColor="#6B696B" Font-Bold="True" ForeColor="#FFFFFF" />

                            </asp:Login>


===============================================

Here is my login_Authenticate

C#
protected void login_Authenticate(object sender, AuthenticateEventArgs e)
    {       
        string newUsername1 = loginDetails.UserName.TrimStart(' ');
        string newUsername2 = newUsername1.TrimEnd(' ');
        if (!IsPostBack)
        {            
                Session["x"] = txtUsename.Text;
                DataTable dt = new DataTable();
                dt = DLL.GetPersonId(txtUsename.Text, txtPassword.Text);
                Response.Redirect("Default.aspx");           
        }
        Session["Username"] = newUsername2.ToLower();
        if (Membership.ValidateUser(newUsername2.ToLower(), loginDetails.Password))
        {          
            e.Authenticated = false;
            if (e.Authenticated == true)
            {
                DataTable dt = DLL.GetPersonId(newUsername2.ToLower(), loginDetails.Password);
                if (dt.Rows.Count > 0)
                {
                    Session["Admin_Number"] = dt.Rows[0]["admin_Number"].ToString();
                }
            }
        }
        else
        {
            e.Authenticated = false;
        }
    }


====================================================
This is my GetPerson method

C#
public DataTable GetPersonId(string username, string password)
       {
           DataTable dataTable = new DataTable();

           using (SqlConnection con = new SqlConnection(ConnString))
           {
               SqlCommand cmd = con.CreateCommand();
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.CommandText = "GetUserID";



               cmd.Parameters.Add(new SqlParameter("@Admin_Username", SqlDbType.NVarChar, 10));
               cmd.Parameters["@Admin_Username"].Value = username;
               cmd.Parameters.Add(new SqlParameter("@Admin_password", SqlDbType.NVarChar, 10));
               cmd.Parameters["@Admin_Password"].Value = password;


               SqlDataAdapter da = new SqlDataAdapter(cmd);

               try
               {
                   con.Open();
                   da.Fill(dataTable);
               }
               catch (SqlException ex)
               {
                   throw new ApplicationException(ex.Message);
                   throw new ApplicationException("Error reading from database.");
               }
               return dataTable;
       }

When i try to put my username and password it always says wrong username and password

Please help!!!
Posted
Updated 11-Jun-13 0:06am
v2

1 solution

C#
e.Authenticated = false;
if (e.Authenticated == true)


You've got a condition and for both outcomes you set the authentication to false. That's not going to help!

Also, I think you want a return after the Response.Redirect, although quite what you're trying to do there I don't understand.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900