Java – accepts multiple user names and passwords

How do I accept multiple user names and passwords using the following code? if(value1.equals(“username”)&& value2. equals(“password”))

Solution

Maybe you're just after such a simple cycle:

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);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>