> ## Documentation Index
> Fetch the complete documentation index at: https://docs.2024921.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# 管理后台

> 管理员认证与会话接口

## 首次设置密码

```http theme={null}
POST /api/admin/setup
X-Setup-Key: <BLOG_ADMIN_SETUP_KEY>
```

**请求体：**

```json theme={null}
{
  "password": "新管理员密码"
}
```

<Info>
  仅在数据库无管理员密码时可用。一次性接口。
</Info>

## 登录

```http theme={null}
POST /api/admin/login
```

**请求体：**

```json theme={null}
{
  "password": "管理员密码"
}
```

**响应：**

```json theme={null}
{
  "ok": true,
  "token": "32字节hex会话Token",
  "mustChange": false
}
```

### 安全机制

| 机制    | 说明                         |
| ----- | -------------------------- |
| 密码验证  | PBKDF2-SHA256（100,000 次迭代） |
| Token | 32 字节随机 hex，7 天有效          |
| 限流    | 同一 IP 5 次失败锁定 15 分钟        |
| 强制改密  | `mustChange: true` 时需先改密码  |

## 登出

```http theme={null}
POST /api/admin/logout
Authorization: Bearer <token>
```

Token 立即作废。

## 修改密码

```http theme={null}
PUT /api/admin/password
Authorization: Bearer <token>
```

**请求体：**

```json theme={null}
{
  "currentPassword": "当前密码",
  "newPassword": "新密码"
}
```

## 认证方式

所有需要认证的接口在请求头中携带 Token：

```
Authorization: Bearer <token>
```

Token 存储在浏览器 `localStorage`，7 天有效。
