Hello,
I have an issue and not sure why it causes it? For some reason, It failed to login because the password is invalid eventhough I checked the password and username that save in the .mdb are correct. I can login for 1 or 2 times then login again, it failed to login because the invalid password, I checked the password again to make sure it is correct, yes it is correct but it failed to login with the right password. Does anyone knows why and how do I solve this problem? thanks
heloo..
pls post u code here?
i will check it for u..
or u can try this :
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb.OleDbCommand
Imports System.Collections.Specialized.NameValueCollection
Imports System.Configuration.ConfigurationManager
Partial Class Login
Inherits System.Web.UI.Page
Dim username As String
Dim password As String
Protected Sub LoginAction_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LoginAction.Click
Dim cn As New SqlConnection
Dim cm As New SqlCommand
Dim dr As SqlDataReader
username = usernametext.Text
password = passwordtext.Text
Try
cn.ConnectionString = ConfigurationManager.AppSettings("connectionstring")
cn.Open()
cm.Connection = cn
cm.CommandText = "select * FROM [customer] where user_id='" & username & "' and password='" & password & "'"
dr = cm.ExecuteReader()
dr.Read()
If dr.HasRows Then
System.Web.Security.FormsAuthentication.RedirectFromLoginPage(username, False)
ElseIf FormsAuthentication.Authenticate(usernametext.Text, passwordtext.Text) Then
Response.Redirect("admin/Barang.aspx")
Else
labelmsg.Text = "Incorrect username or password!"
End If
Catch ex As Exception
End Try
End Sub
End Class
ok.. let's try it...
thanks Hardy for replying,
When I tested in the localhost, login and logout multiple times are fine, no invalid or timeout what so ever, but when posted in the server production and tested with same username and password. It works for one or three times then I try to re-login again, it failed to login because of invalid password eventhough I re-checked the directory to the user.mdb, the password and the username. They are correct but still failed to login because the invalid passord. So I'm wondering why is it? and what causes it?
privatevoid BtnNext_Click(object sender, System.EventArgs e){
string retVal;int count;
//string sLog;
divstatus.InnerHtml ="";retVal =PubFunc.ValidateUser(TxtUser.Text.Trim(), TxtPassword.Text.Trim());
PubFunc.TraceLog(retVal,"UserName and Password");count = retVal.IndexOf("Error");
if (count > -1 || retVal.Trim().Length < 1)divstatus.InnerHtml +="Login Failed!!!";
else
{
divstatus.InnerHtml +="";Session.Add("user", TxtUser.Text.Trim());
Session.Add("password", TxtPassword.Text.Trim());Session.Add("userid", retVal);
Response.Redirect("Form2.aspx");}
}
Here is myPubFunc Class forvalidate user:
publicstaticstring ValidateUser(string strUserName,string strPassword)
{
string mySelectQuery, myConnString;string retVal;
OleDbConnection myConnection;OleDbCommand myCommand;
OleDbDataReader myReader;try
{
mySelectQuery ="Select id from Users where StrComp(username, " +"'" + strUserName +"', 0) = 0" +" and StrComp(passwd, " +"'" + strPassword +"', 0) = 0";myConnString ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +ConfigurationManager.AppSettings.Get("UserDb");
myConnection =newOleDbConnection(myConnString);myCommand =newOleDbCommand(mySelectQuery, myConnection);myConnection.Open();
myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
if (myReader.Read())retVal = myReader["id"] +"";
else
retVal ="Error: Invalid User";myReader.Close();
myConnection.Close();
}
catch (Exception e){
retVal = ("Error: " + e.Message);}
return retVal;}
wah.... u are using high code...
but i will check it for u too ..
okay..
hello orchid..
sory for waiting...
is your login.aspx like that?
label1 txtuser
label2 txtpassword
button
or add something?
pls give more detail code aboutdivstatus andPubFunc..
ok...
This may be the cause.. take a look at this article:http://weblogs.asp.net/scottgu/archive/2006/04/22/Always-set-the-_2200_applicationName_2200_-property-when-configuring-ASP.NET-2.0-Membership-and-other-Providers.aspx
Hi,
Based on my understanding, you can log in your asp.net application one or two times successfully. When you try to log in again, you cannot log in successfully. If I have misunderstood you, please feel free to let me know.
We can log in your application some times, which indicates that the database connection string is correct in your server.
To better understand your issue, could you please confirm the following information:
Based on your code, we cannot make sure that the cause of logging in unsuccessfully is the error password. We can insert the breakpoint in the source code to inspect if the exception is raised.
publicstaticSqlConnection GetConnection()
{
try
{
Con =newSqlConnection();//Con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Windows"].ConnectionString;
Con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["SQL"].ConnectionString;if (Con.State == System.Data.ConnectionState.Closed){
Con.Open();
}
return Con;}
catch (SqlException ex){
thrownewException(ex.ToString());}
catch (Exception ex){
thrownewException(ex.ToString());}
returnnull;}
hardy:
hello orchid..
sory for waiting...
is your login.aspx like that?
label1 txtuser
label2 txtpassword
button
or add something?
pls give more detail code about divstatus and PubFunc..
ok...
Thanks hardy for your help and sorry for waiting, I still sometimes have this trouble login to the webapp and sometimes not, this is driving me crazy hihihihi... Here is what I have in the login.aspx:
label1 txtuser.Text
label2 txtpassword.Text
About the divstatus.InnerHtml = "";
- divstatus is the HtmlGenericControl Login.divstatus
-InnerHtml - is a string HtmlContainerControl.innerHtml (gets or sets the contain found between openning and closing tags that specified the Html server control) and I assigned that to null/empty before page load or check the validate username and password.
And about the "PubFunc", it is a class PubFunc and I'm refering to the function called "ValidateUser" to validate whether a user's id/password is valid or not and this function in this Class PubFunc
ChanceUSC:
This may be the cause.. take a look at this article:http://weblogs.asp.net/scottgu/archive/2006/04/22/Always-set-the-_2200_applicationName_2200_-property-when-configuring-ASP.NET-2.0-Membership-and-other-Providers.aspx
Thanks ChanceUSC, Thomas Sun and sandeepthekka for all your help.
I read the article and try to add in the default applicationName="/" in the webconfig and see if it helps to prevent the login problems, but it hasn't resolve the issue yet. I still have the same issue, sometimes I can login fine and somtimes not. Not sure what's going on. I set the try and catch error and sometime it works fine and sometime it didn't read in the
if (myReader.Read())
retVal = myReader["id"] + "";
sory orchid, i am confusion...
but my friend said that ur problem in strcom code...
ok, i will let u know if i have resolve it...
0 comments:
Post a Comment