ajaj22633-bit

Create a NeoForge mod (Java 21, NeoForge 21.1.x, target Minecraft 1.21.1) with a full login/authentication system.

Mod metadata (META-INF/neoforge.mods.toml)

  • modLoader = "javafml"
  • authors = "Nawaz Ahmad"
  • standard mandatory fields: modid, displayName, version, description

Setup

  • Gradle build using the NeoForge ModDevGradle plugin
  • Main class annotated @Mod("modid"), IEventBus injected via constructor
  • Game-logic listeners on NeoForge.EVENT_BUS; lifecycle/setup listeners on the mod event bus

Commands (Brigadier, via RegisterCommandsEvent)

  • /register <password> <confirmPassword> — creates an account for a new player
  • /login <password> — authenticates a registered player
  • /logout — logs the player out manually
  • /changepassword <old> <new> — change password while logged in
  • Only /login, /register, /help usable before auth — check auth state at the start of every command

Auth enforcement (until logged in)

  • PlayerLoggedInEvent — mark player "pending auth", store their join position
  • No direct cancellable move event exists in NeoForge (unlike Bukkit) — freeze instead: in PlayerTickEvent.Pre, if unauthenticated, teleport back to the stored join position and zero velocity (a Mixin on the movement packet is a tighter alternative)
  • ServerChatEvent — cancel and send a reminder if unauthenticated
  • BlockEvent.BreakEvent / BlockEvent.EntityPlaceEvent — cancel if unauthenticated
  • PlayerInteractEvent (block/entity/item) — cancel if unauthenticated
  • Kick (ServerPlayer#connection.disconnect(...)) if not authenticated within a configurable timeout (default 60s)

Security

  • Never store plain-text passwords — BCrypt, or SHA-256 + per-user random salt
  • Configurable max login attempts (default 3), then temp kick/cooldown
  • Optional IP-based auto-login (same username + same IP, toggleable)

Storage

  • SQLite, async (don't block the server thread on DB calls)
  • Table: uuid, username, password_hash, salt, last_ip, registered_at, last_login
  • Bundle the SQLite JDBC driver into the mod jar (Gradle Shadow plugin) — NeoForge doesn't ship one
  • Storage layer in its own class so MySQL can be added later

Config

  • Use NeoForge's own config system (ModConfigSpec) instead of a raw file: session-timeout-seconds, max-login-attempts, allow-ip-autologin, min-password-length
  • Customizable kick/login-required/register-required messages

Structure

  • Packages: main mod class, AuthManager, DatabaseManager, event listeners, commands, config
  • No Bukkit-style permission nodes in vanilla NeoForge — gate bypass on operator level (player.hasPermissions(2)) unless a separate permissions mod is already in use
Kodari AI
KodariSep 21 at 2:23 am 11
NeoForgeAuthSystem
A comprehensive NeoForge authentication plugin for Minecraft 1.21.1 featuring SQLite-backed account storage with BCrypt password hashing, session management with configurable timeouts, IP-based auto-login, and brute-force protection. Includes Brigadier commands for registration, login, logout, and password changes, plus event-driven auth enforcement that freezes unauthenticated players, blocks chat/block interactions, and kicks idle sessions. Features async database operations, ModConfigSpec configuration, operator-level bypass, and a modular storage layer supporting future MySQL migration.
  1. Create the NeoForge 1.21.1 Gradle project and mod metadata.

  2. Implement asynchronous SQLite storage with salted SHA-256 password hashing.

  3. Add authentication state management, command handlers, config, and gameplay enforcement listeners.

Created the SecureAuth NeoForge 1.21.1 project with:

  • ModDevGradle + shaded SQLite JDBC dependency

  • Server-side NeoForge configuration and metadata

  • Async SQLite account storage

  • Salted SHA-256 password hashing

  • Registration, login, logout, and password-change commands

  • Login timeout, attempt limit, optional IP auto-login, and operator bypass

  • Authentication freeze plus chat, interaction, placement, and breaking restrictions

ajaj22633-bit

Fix all error on mod

Kodari AI
KodariSep 21 at 2:27 am 12
  • Repair invalid NeoForge/mod-container wiring and command registration.

  • Correct event and player API usage for NeoForge 1.21.1.

  • Make the Gradle packaging and database lifecycle build-safe.

Fixed the primary NeoForge 1.21.1 build/API errors:

  • Corrected command registration to receive the AuthManager directly instead of invalid mod-instance lookup.

  • Fixed event-bus listener typing for RegisterCommandsEvent.

  • Reworked interaction enforcement to use cancellable PlayerInteractEvent subclasses.

  • Removed invalid cross-level teleport usage and incompatible disconnect-state call.

  • Added the missing Gradle mod_version property used by neoforge.mods.toml.

  • Ensured the shaded SQLite jar is included during assembly.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
13 740
src/main/java/com/nawazahmad/secureauth/SecureAuthMod.java
package com.nawazahmad.secureauth;

import com.nawazahmad.secureauth.auth.AuthManager;
import com.nawazahmad.secureauth.command.AuthCommands;
import com.nawazahmad.secureauth.config.AuthConfig;
import com.nawazahmad.secureauth.database.DatabaseManager;
import com.nawazahmad.secureauth.event.AuthEventListener;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.RegisterCommandsEvent;

@Mod(SecureAuthMod.MOD_ID)
public final class SecureAuthMod {
    public static final String MOD_ID = "secureauth";

    private final DatabaseManager databaseManager;
    private final AuthManager authManager;

    public SecureAuthMod(IEventBus modEventBus, ModContainer modContainer) {
        modContainer.registerConfig(net.neoforged.fml.config.ModConfig.Type.SERVER, AuthConfig.SPEC);

        this.databaseManager = new DatabaseManager();
        this.authManager = new AuthManager(databaseManager);

        modEventBus.addListener(this::onCommonSetup);
        NeoForge.EVENT_BUS.register(new AuthEventListener(authManager));
        NeoForge.EVENT_BUS.addListener((RegisterCommandsEvent event) -> AuthCommands.register(event, authManager));
    }

    private void onCommonSetup(net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent event) {
        event.enqueueWork(databaseManager::initialize);
    }
}