class TomlAuth implements AuthProvider {

  @Override
  public void authenticate(
      final JsonObject authInfo, final Handler<AsyncResult<User>> resultHandler) {
    final String username = authInfo.getString("username");
    if (username == null) {
      resultHandler.handle(Future.failedFuture("No username provided"));
      return;
    }

    final String password = authInfo.getString("password");
    if (password == null) {
      resultHandler.handle(Future.failedFuture("No password provided"));
      return;
    }

    vertx.executeBlocking(
        f -> {
          TomlParseResult parseResult;
          try {
            parseResult = Toml.parse(options.getTomlPath());
          } catch (IOException e) {
            f.fail(e);
            return;
          }

          final TomlTable userData = parseResult.getTableOrEmpty("Users." + username);
          if (userData.isEmpty()) {
            f.fail("User not found");
            return;
          }

          final TomlUser tomlUser = readTomlUserFromTable(username, userData);
          if ("".equals(tomlUser.getPassword())) {
            f.fail("No password set for user");
            return;
          }

          checkPasswordHash(
              password,
              tomlUser.getPassword(),
              rs -> {
                if (rs.succeeded()) {
                  f.complete(tomlUser);
                } else {
                  f.fail(rs.cause());
                }
              });
        },
        false,
        res -> {
          if (res.succeeded()) {
            resultHandler.handle(Future.succeededFuture((TomlUser) res.result()));
          } else {
            resultHandler.handle(Future.failedFuture(res.cause()));
          }
        });
  }

  public  TomlAuth(final Vertx vertx, final TomlAuthOptions options);

}