Reputation: 519
I'm sending a username and password to a website for authentication purposes, after all is said and done and I've retrieved the results from the server, I've placed the results in a variable called 'response' To this point everything is working correctly
response = sb.toString();
Toast.makeText(this,"Returned Value: "+ response,0).show();
The value seen in the above Toast is the value being returned by the php script. I've used both a valid user and an invalid user and the Toast displayed above shows the correct value (i.e. "Good Login" or "Login Failed") returned by the server. I want to test for those results so I can start the appropriate activity so I've put in some test "if" statements
if("Good Login".equals(response)){
Toast.makeText(this, "Registered User" + mUsername, 0).show();
}
if("Login Failed".equals(response)){
Toast.makeText(this, "Sorry You're Not A Registered Subscriber",0).show();
}
I'm getting nothing from either one. I've also tried
if(response.equals("Good Login")){
Toast.makeText(this, "Registered User" + mUsername, 0).show();
}
if(response.equals("Login Failed")){
Toast.makeText(this, "Sorry You're Not A Registered Subscriber",0).show();
}
With the same results. Not sure what else to test for. Is there a better way to test for success or failure?
Thanks
Upvotes: 0
Views: 353
Reputation: 3165
The Java string equals function is fully case/spacing sensitive compare.
So if:response = "Good Login "
or if it contains extra-spaces or non-printing characters then it will fail the test.
It would be a good idea to strip all whitespace, even the internal ones. Here's a SO question about doing just that. Also use String.equalsCaseInsesitive()
when doing that actual comparison.
Upvotes: 0
Reputation: 7631
Upvotes: 0
Reputation: 597254
Debug (or print) the exact value of the response
variable.
It is likely that there are whitespaces, so you may need to have response = response.trim()
Upvotes: 2