To jest cały mój kod.
Brakuje mi jedynie matody readCredentials(). Plik .conf zawiera napisy Login, Password.
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
import java.nio.file.Files;
public class Skynet {
private String login = "Reese";
private String password = "#Terminate";
public static void main(String args[]) {
Skynet skynet = new Skynet();
skynet.run();
}
public void run() {
readCredentials();
printSkyNetLogo();
runLoginPanel();
}
private void runLoginPanel() {
String readLogin;
String readPassword;
boolean credentialsOK;
do {
readLogin = getTextFromInput("Login");
readPassword = getTextFromInput("Password");
credentialsOK = verifyCredentials(readLogin, readPassword);
if (!credentialsOK) {
System.out.println("Wrong login or password. Try again.");
}
} while (!credentialsOK);
System.out.println();
System.out.println("Welcome to SKYNET...");
}
private String getTextFromInput(String label) {
Scanner in = new Scanner(System.in);
String login, password;
System.out.print("Enter your username: ");
login = in.nextLine();
System.out.print("Enter your password: ");
password = in.nextLine();
return null;
}
private boolean verifyCredentials(String login, String password) {
return this.login.equals(login) && this.password.equals(password);
}
private void readCredentials() {
// TODO read credentials from the file "..skynet.conf"
// TODO print "INFO System reconfigured..." if correctly read
// TODO print "INFO No valid conf data" if could not read credentials
private void printSkyNetLogo() {
File logoFile = new File("logo.txt");
try (BufferedReader reader = Files.newBufferedReader(logoFile.toPath())) {
String line = null;
while((line = reader.readLine()) !=null) {
System.out.println(line);
}
}catch(IOException x) {
System.err.format("IOException: %s", x);
}
}
}