How to accept multiple username and password using the following code? if (value1.equals("username") && value2.equals("password"))
Perhaps you're just after a simple loop like this:
String[][] userPass = { { "user1", "pass1" },
{ "user2", "pass2" },
{ "user3", "pass3" } };
String value1 = "userToCheck";
String value2 = "passToCheck";
boolean userOk = false;
for (String[] up : userPass)
if (value1.equals(up[0]) && value2.equals(up[1]))
userOk = true;
System.out.println("User authenticated: " + userOk);
if ((value1.equals("username1") && value2.equals("password1")) ||
(value1.equals("username2") && value2.equals("password2")))
I advise you to do some decent username/password checking because hardcoding is not secure (and flexible)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With