0

I am using Amazon Web Services s3, and am using it to, - open a connection (working fine) - open an input stream from a text file that has usernames and passwords listed username,password username,password ... all that works fine, I run into issues when trying to check if a username matches with a password.

Take a look,

            while (INFINITE == 1) {
            System.out.println("ran");
            if (tryToLogin == true) {
                System.out.println("ran2");
                tryToLogin = false;
             BufferedReader br = new BufferedReader(new InputStreamReader(object.getObjectContent()));
             String lineValue = null;
             while((lineValue = br.readLine()) != null && loggedInAs == null){
                 String splitResult[] = lineValue.split(",");
               if ("saucymeatman" ==  splitResult[0] && "mufasa" == splitResult[1]) {
                loggedInAs = splitResult[0];
                System.out.println("logged in");
             //ui.usernameLogin.getText()
               }
               else {
                    System.out.println("SPLIT 0 : " + splitResult[0]);
                    System.out.println("SPLIT 1 : " + splitResult[1]);
               }
             }
             }
        }

Even though "saucymeatman" == splitResult[0] && "mufasa" == splitResult[1] It does not print "Logged in" or set loggedInAs to anything. I am sure that splitResult[0] equals "saucymeatman" because it prints "SPLIT 0 : saucymeatman".

Thanks in advance.

1 Answers1

0

Do not use == to compare String values; use the equals method of the String class. The == operator compares objects references to determine if they refer to the same object; it doesn't compare string contents.

rgettman
  • 172,063
  • 28
  • 262
  • 343