Depending on the complexity or level of interaction you require, this could be done with something as simple as making a GET request to a particular page on your web server, and supplying the necessary information in the query string (alternatively you could use POST).
// Construct the query string with the proper username and password
URL url = new URL("http://www.yoursite.com/verify.php?username=happy&password=pants");
try (BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()))) {
StringBuilder sb = new StringBuilder();
for (String s; (s = in.readLine()) != null;)
sb.append(s);
switch (sb.toString().trim()) {
case "welcome":
JOptionPane.showMessageDialog(null, "Welcome!");
// Proceed to game
break;
case "shut up and pay me":
JOptionPane.showMessageDialog(null, "You owe me money first!");
break;
case "no such user":
JOptionPane.showMessageDialog(null, "Go away!");
// Recursively delete all their files...
break;
}
}
Where verify.php has some PHP code that looks something like
// Set up database stuff...
// Query the database
$query = sprintf("SELECT * FROM friends users WHERE username='%s' AND password='%s'",
mysqli_real_escape_string($_GET["username"]),
mysqli_real_escape_string($_GET["password"]));
if (($result = mysqli_query($query)) && ($row = mysqli_fetch_assoc($result))) {
if ($row["license"] == "premium") {
echo "welcome";
} else {
echo "shut up and pay me";
}
} else {
echo "no such user";
}
But this is just a very basic example of what you could do, and shouldn't be followed verbatim. You probably shouldn't pass these values through the query string of the URL (perhaps prefer a POST rather than a GET here), and above all else you shouldn't store or pass the password in plain text either (i.e., hash it first using MD5, SHA1, or another hash of your choice). I only did this for the sake of simplicity.
For anything more complex, you might require one of the other methods you've been given, such as the use of sockets, web services, etc.
If you'd like more information on working with URLs in Java, that can be found here. Or if you'd like more information on PHP's Mysqli, you can get that here, or substitute your own package of choice like PEAR.