Implement the return value of the checkCredentials() method to set a basic authentication.
Setting up a server with HttpServer
Set a basic authentication
Report a typo
Sample Input 1:
James Gosling
jm!gosling#1995Sample 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)
);
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.