There is a code:
public static Map<String, String> getUsers() { Map<String, String> users = new HashMap<>(); String path = "users"; try { List<String> lines = Files.readAllLines(Paths.get(path), Charset.forName("UTF-8")); try { for (String val: lines) { String[] field = val.trim().split(" "); users.put(field[0], field[1]); } } catch (ArrayIndexOutOfBoundsException | NullPointerException e) { System.out.println(e.getMessage()); } } catch (IOException e) { Logs.write("unable to open users file"); System.out.println(e.getMessage()); } return users; } The data is taken from the file line by line, and the values are separated by commas. Then everything is recorded in the HashMap . What is the problem: containsKey() always returns false for the first HashMap element, including if it is only one. Debagger shows that this item in HashMap is.
try { if (users.containsKey(credentials[0])) { if (users.get(credentials[0]).equals(credentials[1])) { logged = true; // db = credentials[2]; writer.println(1); } else { writer.println(0); } } else { writer.println("Suck"); } } catch (Exception e) { System.out.println(e); }
а значения разделены запятыми. Attention question. Where isString[] field = val.trim().split(" ");separators commas? - Sergey