Set a basic authentication

Report a typo

Implement the return value of the checkCredentials() method to set a basic authentication.

Sample Input 1:

James Gosling
jm!gosling#1995

Sample Output 1:

The auth result of James Gosling is true!
Write a program in Java 17
import java.util.*;
import com.sun.net.httpserver.BasicAuthenticator;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String username = sc.nextLine();
String password = sc.nextLine();

BasicAuthenticator auth = new BasicAuthenticator("realm") {
@Override
public boolean checkCredentials(String username, String password) {
// implement the method here
}
};

System.out.printf(
"The auth result of %s is %b!",
username, auth.checkCredentials(username, password)
);
}
}
___

Create a free account to access the full topic