M using asp login control . here is my code
<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
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
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!!!