Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accepting multiple username and password

Tags:

java

How to accept multiple username and password using the following code? if (value1.equals("username") && value2.equals("password"))

like image 231
LockOn Avatar asked Dec 27 '25 16:12

LockOn


2 Answers

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);
like image 166
aioobe Avatar answered Dec 31 '25 08:12

aioobe


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)

like image 29
RvdK Avatar answered Dec 31 '25 07:12

RvdK