-2

I must have some sort of syntax error somewhere, because both correctip and loginip are equal but my code is still saying they are not equal.

        if(correctip != loginip){
            event.disallow(null, "Access is denied to user " + name + ". If you believe this is in error, contact an admin.");
            System.out.println(loginip);
            System.out.println(correctip);
            System.out.println("[Denied] HIGHRISKUSER " + name + " denied login. IP Att: " + loginip + " | IP Cor: " + correctip);
        }else{
            System.out.println("[Allowed] HIGHRISKUSER " + name + " allowed login. IP Att: " + loginip + " | IP Cor: " + correctip);
        }

Both correctip and loginip are EXACTLY equal. Is there something else that could be causing problems?

DannyF247
  • 628
  • 4
  • 14
  • 35

3 Answers3

4

correctip and loginip might be String. In that case, you should use the equals comparator:

if(correctip != null && correctip.equals(loginip)) {
    //your logic goes here...
}
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
1

if both variables are strings, you need to use correctip.equals(loginip) or correctip.equalsIgnoreCase(loginip) to compare them.

sgowd
  • 2,242
  • 22
  • 29
1

What is the type of loginip and correctip?

Per your statement, I assume that the type should not be primitive(For example: int, long, short and so on). Instead, it would be a object (probably be string). so loginip or correctip is actually a reference of these two objects.

The equal-sign only assures the equality of its reference address. To compare two objects, you should use method equals or equalsIgnoreCase instead of =.

C.c
  • 1,905
  • 6
  • 30
  • 47