0

I am having a problem when using a response from a HttpClient in an IF statement. I am using it to verify username and password for a login, here is the login class

public class loginClass {
    public static String verify(EditText username, EditText password){
        String UN = username.getText().toString();
        String PW = password.getText().toString();

        String PWencrypt = Encrypt.md5(PW);
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://cstudios.co.uk/cstudiosApps/Login.php?UN="+UN+"&PW="+PWencrypt);
        try{
            // Execute HTTP Post Request
            BasicHttpResponse response = (BasicHttpResponse) httpclient.execute(httppost);
            String Val = EntityUtils.toString(response.getEntity());
            String[] Value = Val.split(",");
            if(Value[1] == "FAIL"){
                return "False";
            }else{
                String UserID = Value[1];
                return UserID;
            }
        } catch (ClientProtocolException e) {
            return "Error";
        } catch (IOException e) {
            return "Error";
        }
    }
}

Here is the code for the PHP file:

<?php
//Getting Username from APP
$UN = $_GET["UN"];
$UN = mysql_real_escape_string($UN);
$PW = $_GET["PW"];
// Create Connection
$con=mysqli_connect($URL,$username,$password,$Database);
// Check connection
if (mysqli_connect_errno($con))
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//Login Query
$GetPW = mysqli_query($con,"SELECT * FROM users WHERE Username='$UN'");
while($row = mysqli_fetch_array($GetPW))
    {
        $PWtest=$row['Password'];
        $USERid=$row['UserID'];
    }
if($PW==$PWtest)
    {
        echo "," . $USERid . ",";//for use of APP
    }else{
        echo ',FAIL,';
    }
//Close Connection
mysqli_close($con);
?>

I set the Sql Variables above I just didn't want to paste that, any help on this will be great, the issue comes when using

if(Value[1] == "FAIL")

as it never returns false... thanks in advance for your help.

1
  • Use String's equals method to compare string contents, not the == operator. Commented Nov 22, 2013 at 1:18

1 Answer 1

1

Use .equals () method for comparing strings in java.

Sign up to request clarification or add additional context in comments.

1 Comment

You won't do it again :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.