Hi,
I have a problem with my login control. I changed the code in order to use my own database (SQL Server 2005) and no matter what i do i get the message "Your login attempt was not successful. Please try again. "!!!
in the web.config file i chose my own connection string leading to my database, so i don't use the default database for the login authorization.
Do i have to change anything else in there?
Check out my code below
Please anyone who can help i really appreciate it!!!!!!!
When I debugged the code I get the exception on the line 55
public partial class _Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
try
{
string uname = Login1.UserName.Trim(); //Get the username from the control
string password = Login1.Password.Trim(); //get the Password from the control
bool flag = AuthenticateUser(uname, password);
if (flag == true)
{
e.Authenticated = true;
Login1.DestinationPageUrl = "Admin.aspx";
}
else
{
e.Authenticated = false;
}
}
catch (Exception)
{
e.Authenticated = false;
}
}
private bool AuthenticateUser(string uname, string password)
{
bool bflag = false;
string connString = "Data Source = localhost; Initial Catalog = Telemedicine; User Id=sa; Password=sa;";
string strSQL = "select * from Administrator where UserName =’" + uname + "‘ AND Password =’" + password + "‘";
DataSet userDS = new DataSet();
SqlConnection m_conn;
SqlDataAdapter m_dataAdapter;
SqlCommand m_Command;
try
{
m_conn = new SqlConnection(connString);
m_conn.Open();
m_dataAdapter = new SqlDataAdapter(strSQL, m_conn);
m_dataAdapter.Fill(userDS);
m_conn.Close();
}
catch (Exception ex)
{
userDS = null;
}
if (userDS != null)
{
if (userDS.Tables[0].Rows.Count > 0)
bflag = true;
}
return bflag;
}
}
thank u very much
Nikolas