> For the complete documentation index, see [llms.txt](https://impoo.gitbook.io/authenticationsystem/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://impoo.gitbook.io/authenticationsystem/developers/authmanager.md).

# AuthManager

`AuthManager` handles the authentication lifecycle: registration, login, password management, IP checks, premium handling, and authentication state queries.

Obtain it from `AuthSystemApi`:

```java
AuthManager authManager = api.getAuthManager();
```

## Methods

### onJoin(Player player)

```java
void onJoin(Player player)
```

Handles a player joining the server. Marks the player as unauthenticated and starts the authentication timeout.

**Parameters:**

* `player` — the player who joined

**Returns:** `void`

### onQuit(Player player)

```java
void onQuit(Player player)
```

Handles a player quitting the server. Cleans up the player's authentication state.

**Parameters:**

* `player` — the player who quit

**Returns:** `void`

### register(Player player, String password, String confirmPassword)

```java
void register(Player player, String password, String confirmPassword)
```

Registers a new player account. The password is confirmed by comparing `password` and `confirmPassword`. On success the player is marked as authenticated. The password is hashed with BCrypt and stored in the database.

**Parameters:**

* `player` — the player to register
* `password` — the chosen password
* `confirmPassword` — the password confirmation (must match `password`)

**Returns:** `void`

### login(Player player, String password)

```java
void login(Player player, String password)
```

Authenticates a player by verifying their password against the stored hash.

**Parameters:**

* `player` — the player logging in
* `password` — the plain-text password to verify

**Returns:** `void`

### changePassword(Player player, String oldPassword, String newPassword)

```java
void changePassword(Player player, String oldPassword, String newPassword)
```

Changes a player's password after verifying the old one.

**Parameters:**

* `player` — the player changing their password
* `oldPassword` — the current password (for verification)
* `newPassword` — the new password to set (minimum 6 characters)

**Returns:** `void`

### adminChangePassword(Player admin, String targetName, String newPassword)

```java
void adminChangePassword(Player admin, String targetName, String newPassword)
```

Changes a player's password without verifying the old one. Admin-only operation.

**Parameters:**

* `admin` — the admin performing the action
* `targetName` — the name of the target player
* `newPassword` — the new password to set (minimum 6 characters)

**Returns:** `void`

### unregister(Player admin, String targetName)

```java
void unregister(Player admin, String targetName)
```

Removes a player's account from the database. Irreversible. If the target player is online they will be moved back to the waiting-auth state.

**Parameters:**

* `admin` — the admin performing the action
* `targetName` — the name of the player to unregister

**Returns:** `void`

### checkIp(Player admin, String targetName)

```java
void checkIp(Player admin, String targetName)
```

Retrieves and displays a player's last known IP address.

**Parameters:**

* `admin` — the admin requesting the information
* `targetName` — the name of the player to look up

**Returns:** `void`

### handlePremium(Player player)

```java
void handlePremium(Player player)
```

Handles premium player authentication. Premium players confirm their identity within 10 seconds.

**Parameters:**

* `player` — the premium player

**Returns:** `void`

### isAuthenticated(UUID uuid)

```java
boolean isAuthenticated(UUID uuid)
```

Checks whether a player is fully authenticated.

**Parameters:**

* `uuid` — the unique ID of the player

**Returns:** `boolean` — `true` if authenticated, `false` otherwise

### isWaitingAuth(UUID uuid)

```java
boolean isWaitingAuth(UUID uuid)
```

Checks whether a player is currently in the authentication waiting state (has joined but not yet registered or logged in).

**Parameters:**

* `uuid` — the unique ID of the player

**Returns:** `boolean` — `true` if waiting for authentication, `false` otherwise

## Method summary table

| Method                | Parameters                   | Returns   | Description              |
| --------------------- | ---------------------------- | --------- | ------------------------ |
| `onJoin`              | `Player`                     | `void`    | Handle player join       |
| `onQuit`              | `Player`                     | `void`    | Handle player quit       |
| `register`            | `Player`, `String`, `String` | `void`    | Register new account     |
| `login`               | `Player`, `String`           | `void`    | Authenticate player      |
| `changePassword`      | `Player`, `String`, `String` | `void`    | Change own password      |
| `adminChangePassword` | `Player`, `String`, `String` | `void`    | Admin password reset     |
| `unregister`          | `Player`, `String`           | `void`    | Delete account           |
| `checkIp`             | `Player`, `String`           | `void`    | Check player IP          |
| `handlePremium`       | `Player`                     | `void`    | Handle premium auth      |
| `isAuthenticated`     | `UUID`                       | `boolean` | Check auth state         |
| `isWaitingAuth`       | `UUID`                       | `boolean` | Check waiting auth state |

***

> :bulb: **Tip**: Use `isAuthenticated()` before allowing players to run restricted commands or access protected features.
